DoWhatIMeanSupport.st
author Claus Gittinger <cg@exept.de>
Fri, 28 Jun 2019 09:21:50 +0200
changeset 6078 08c9e2a47dc5
parent 6036 171e12f06b70
child 6082 96c1001f95ef
permissions -rw-r--r--
#OTHER by cg self class name -> self className
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6022
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
     1
"{ Encoding: utf8 }"
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
     2
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
"
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
 COPYRIGHT (c) 2002 by eXept Software AG
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
     5
	      All Rights Reserved
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 This software is furnished under a license and may be used
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
 hereby transferred.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
"
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
"{ Package: 'stx:libwidg2' }"
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
    16
"{ NameSpace: Smalltalk }"
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
    17
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
Object subclass:#DoWhatIMeanSupport
5512
4375d3732703 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5509
diff changeset
    19
	instanceVariableNames:'tree tokens languageOrNil classOrNil methodOrNil contextOrNil
4375d3732703 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5509
diff changeset
    20
		instanceOrNil codeView rememberedScopeNodes rememberedNodes
5980
0ae8756ef72f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5973
diff changeset
    21
		codeAspect partialString partialStringInterval classResolverHook'
5512
4375d3732703 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5509
diff changeset
    22
	classVariableNames:'LastSource LastParseTree LastScanTokens LastChoices
4375d3732703 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5509
diff changeset
    23
		LastCompletedSelectors Verbose'
4375d3732703 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5509
diff changeset
    24
	poolDictionaries:''
4375d3732703 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5509
diff changeset
    25
	category:'System-Support'
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
!
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
    28
Array variableSubclass:#InputCompletionResult
5512
4375d3732703 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5509
diff changeset
    29
	instanceVariableNames:''
4375d3732703 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5509
diff changeset
    30
	classVariableNames:''
4375d3732703 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5509
diff changeset
    31
	poolDictionaries:''
4375d3732703 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5509
diff changeset
    32
	privateIn:DoWhatIMeanSupport
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
    33
!
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
    34
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
!DoWhatIMeanSupport class methodsFor:'documentation'!
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
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
"
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
 COPYRIGHT (c) 2002 by eXept Software AG
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
    40
	      All Rights Reserved
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
 This software is furnished under a license and may be used
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
 only in accordance with the terms of that license and with the
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
 inclusion of the above copyright notice.   This software may not
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
 be provided or otherwise made available to, or used by, any
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
 other person.  No title to or ownership of the software is
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
 hereby transferred.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
"
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
!
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
documentation
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
"
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
    53
    Attention: this is currently being rewritten and refactored.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
    54
    Don't get mad at the ugly (and duplicate) code.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
    55
    Will cleanup when finished.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
    56
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
    misc collected UI support (functional)
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
    58
    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
    59
    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
    60
    places.
3667
acb358ca4b0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3660
diff changeset
    61
    Therefore it is:
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
    62
	1) not needed for standalone executables
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
    63
	2) published here to avoid multiple implementations
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
    [author:]
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
    66
	Claus Gittinger (cg@exept.de)
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
3299
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
! !
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    70
5869
045fb4db55e3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5804
diff changeset
    71
!DoWhatIMeanSupport class methodsFor:'cleanup'!
045fb4db55e3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5804
diff changeset
    72
045fb4db55e3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5804
diff changeset
    73
lowSpaceCleanup
045fb4db55e3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5804
diff changeset
    74
    LastSource := LastParseTree := LastScanTokens := nil.
045fb4db55e3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5804
diff changeset
    75
045fb4db55e3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5804
diff changeset
    76
    "Created: / 01-08-2018 / 22:31:39 / Claus Gittinger"
045fb4db55e3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5804
diff changeset
    77
! !
045fb4db55e3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5804
diff changeset
    78
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    79
!DoWhatIMeanSupport class methodsFor:'code completion'!
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    80
4426
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    81
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
    82
    "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
    83
     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
    84
     nil, if called from the browser.
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
    85
     If nonNil, we can make better guesses, 
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
    86
     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
    87
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    88
    ^ self new
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
    89
        codeCompletionFor: aspect
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
    90
        language: languageOrNil
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
    91
        method:methodOrNil orClass:classOrNil
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
    92
        context:contextOrNil
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
    93
        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
    94
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    95
    "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
    96
!
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
    97
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
    98
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
    99
    "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
   100
     nil, if called from the browser.
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
   101
     If nonNil, we can make better guesses, 
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
   102
     because we actually know what a variable's type is."
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   103
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   104
    ^ self new
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
   105
        codeCompletionForLanguage: languageOrNil 
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
   106
        class:classOrNil 
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
   107
        context:contextOrNil 
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
   108
        codeView:codeView
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   109
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   110
    "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
   111
! !
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   112
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   113
!DoWhatIMeanSupport class methodsFor:'code completion - obsolete'!
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
codeCompletionForClass:classOrNil context:contextOrNil codeView:codeView
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   116
    <resource: #obsolete>
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   117
    "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
   118
     nil, if called from the browser.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   119
     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
   120
     This is not yet done, sigh"
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   121
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   122
    ^ self
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   123
	codeCompletionForLanguage: nil class:classOrNil context:contextOrNil codeView:codeView
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   124
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
   125
    "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
   126
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   127
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   128
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
   129
    <resource: #obsolete>
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   130
    "contextOrNil is the current context, if this is called from the debugger;
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   131
     nil, if called from the browser.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   132
     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
   133
     This is not yet done, sigh"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   134
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   135
    ^ self new
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   136
	codeCompletionForMethod:methodOrNil orClass:classOrNil
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   137
	context:contextOrNil
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   138
	codeView:codeView into:actionBlock
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   139
! !
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   140
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   141
!DoWhatIMeanSupport class methodsFor:'code completion-helpers'!
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   142
3300
e0f4bf68e26a codeCompletion refactored
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
   143
findNodeForInterval:interval in:source
5272
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   144
    "utility"
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   145
    
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   146
    |tree node remember|
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   147
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   148
    interval isEmpty ifTrue: [^ nil].
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   149
    RBParser isNil ifTrue: [^ nil].
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   150
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   151
    source = LastSource ifTrue:[
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   152
        tree := LastParseTree.
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   153
    ] ifFalse:[
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   154
        remember := true.    
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   155
        LastSource := LastParseTree := nil.
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   156
        tree := RBParser
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   157
                parseMethod:source
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   158
                onError:
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   159
                    [:str :err ":nodesSoFar" |
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   160
                        "/ Transcript showCR:'Parse-Error: ',str.
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   161
                        nil
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   162
                    ].
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   163
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   164
        tree isNil ifTrue:[
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   165
            "/ try to parse as an expression
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   166
            tree := RBParser
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   167
                    parseExpression:source
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   168
                    onError:
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   169
                        [:str :err ":nodesSoFar" |
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   170
                            "Transcript showCR:'Parse-Error: ',str."
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   171
                            nil
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   172
                        ].
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   173
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   174
            tree isNil ifTrue:[
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   175
                "/ try to parse the selected text alone as expression
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   176
                remember := false.    
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   177
                tree := RBParser
5973
0608413dbe36 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5931
diff changeset
   178
                    parseExpression:(source copyFrom:(interval start max:1) to:((interval stop max:1) min:source size))
5272
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   179
                    onError:
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   180
                        [:str :err ":nodesSoFar" |
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   181
                            "Transcript showCR:'Parse-Error: ',str."
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   182
                            nil
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   183
                        ].         
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   184
                ^ tree
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   185
            ].
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   186
        ].
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   187
        remember ifTrue:[ 
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   188
            LastSource := source.
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   189
            LastParseTree := tree.
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   190
        ].
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   191
    ].
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   192
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   193
    Error handle:[:ex |
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   194
    ] do:[ 
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   195
        node := tree whichNodeIsContainedBy:interval.
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   196
    ].
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   197
    node isNil ifTrue: [
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   198
        node := tree bestNodeFor: interval.
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   199
        node isNil ifTrue: [
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   200
            node := self findNodeIn:tree forInterval:interval
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   201
        ].
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   202
    ].
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   203
    ^ node
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   204
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   205
    "Modified: / 06-07-2011 / 12:42:53 / cg"
5973
0608413dbe36 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5931
diff changeset
   206
    "Modified: / 17-12-2018 / 17:32:30 / Claus Gittinger"
3300
e0f4bf68e26a codeCompletion refactored
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
   207
!
e0f4bf68e26a codeCompletion refactored
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
   208
3299
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   209
findNodeForInterval:interval in:source allowErrors:allowErrors
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   210
    ^ self new findNodeForInterval:interval in:source allowErrors:allowErrors
4080
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
   211
!
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
   212
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
   213
findNodeForInterval:interval in:source allowErrors:allowErrors mustBeMethod:mustBeMethod
413b8c8a0161 added: #findNodeForInterval:in:allowErrors:mustBeMethod:
Claus Gittinger <cg@exept.de>
parents: 4070
diff changeset
   214
    "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
   215
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   216
    ^ self new
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   217
	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
   218
!
40e860fd2f02 argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents: 3303
diff changeset
   219
40e860fd2f02 argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents: 3303
diff changeset
   220
findNodeForInterval:interval inParseTree:parseTree
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
   221
    ^ 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
   222
!
1cd4b22434a6 code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
   223
5272
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   224
findNodeIn:aTree forInterval:anInterval
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   225
    "utility"
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   226
    
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   227
    |nodeFound wouldReturn|
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   228
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   229
    anInterval isEmpty ifTrue:[^nil].
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   230
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   231
    nodeFound := nil.
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   232
    aTree nodesDo:[:eachNode |
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   233
        (eachNode intersectsInterval:anInterval) ifTrue:[
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   234
            (nodeFound isNil or:[nodeFound == eachNode parent]) ifTrue:[
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   235
                nodeFound := eachNode
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   236
            ] ifFalse:[
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   237
                (nodeFound parent == eachNode parent
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   238
                and:[ eachNode start >= nodeFound start
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   239
                      and:[ eachNode stop <= nodeFound stop ] ]) ifTrue:[
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   240
                ] ifFalse:[
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   241
                    (nodeFound parent notNil
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   242
                    and:[nodeFound parent isCascade and:[eachNode parent isCascade]]) ifFalse:[^ nil]
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   243
                ]
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   244
            ]
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   245
        ] ifFalse:[
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   246
            nodeFound notNil ifTrue:[
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   247
                "/ already found one - beyond that one; leave
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   248
                wouldReturn notNil ifTrue:[wouldReturn := nodeFound].
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   249
            ]
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   250
        ].
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   251
    ].
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   252
"/ (wouldReturn notNil and:[wouldReturn ~~ node]) ifTrue:[self halt].
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   253
    ^ nodeFound
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   254
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
   255
    "Modified: / 20-11-2006 / 12:31:12 / cg"
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
! !
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   258
!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
   259
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   260
classCategoryCompletion:aPartialCategory inEnvironment:anEnvironment
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   261
    "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
   262
     2 entries: 1st: the best (longest) match
6022
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   263
                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
   264
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   265
    |matches best lcName|
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   266
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   267
    matches := IdentitySet new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   268
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   269
    "/ search for exact match
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   270
    anEnvironment allClassesDo:[:aClass |
6022
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   271
        |category|
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   272
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   273
        category := aClass category.
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   274
        (category notNil and:[category startsWith:aPartialCategory]) ifTrue:[
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   275
            matches add:category
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   276
        ]
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   277
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   278
    matches isEmpty ifTrue:[
6022
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   279
        "/ search for case-ignoring match
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   280
        lcName := aPartialCategory asLowercase.
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   281
        anEnvironment allClassesDo:[:aClass |
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   282
            |category|
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   283
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   284
            category := aClass category.
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   285
            (category notNil and:[category asLowercase startsWith:lcName]) ifTrue:[
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   286
                matches add:category
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   287
            ].
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   288
        ].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   289
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   290
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   291
    matches isEmpty ifTrue:[
6022
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   292
        ^ 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
   293
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   294
    matches size == 1 ifTrue:[
6022
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   295
        ^ 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
   296
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   297
    matches := matches asSortedCollection.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   298
    best := matches longestCommonPrefix.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   299
    ^ 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
   300
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   301
    "
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   302
     Smalltalk classCategoryCompletion:'Sys'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   303
     Smalltalk classCategoryCompletion:'System'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   304
     Smalltalk classCategoryCompletion:'System-BinaryStorage'
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   305
    "
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   306
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   307
    "Created: / 10-08-2006 / 13:06:45 / cg"
6022
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   308
    "Modified: / 03-03-2019 / 22:42:47 / Claus Gittinger"
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   309
!
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   310
2830
dbf8a7499ebc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
   311
classNameEntryCompletionBlock
dbf8a7499ebc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
   312
    "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
   313
2977
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   314
    ^ self entryCompletionBlockFor:#'classnameCompletion:inEnvironment:'
2830
dbf8a7499ebc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
   315
2977
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   316
    "Modified: / 10-08-2006 / 13:22:02 / cg"
2830
dbf8a7499ebc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
   317
!
dbf8a7499ebc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
   318
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   319
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
   320
    "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
   321
     2 entries: 1st: the best (longest) match
5052
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   322
                2nd: collection consisting of matching names"
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   323
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   324
    |searchName matches matchedNamesWithoutPrefix ignCaseMatches best isMatchString cls nsPrefix
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   325
     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
   326
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   327
    (words := aPartialClassName asCollectionOfWords) size > 1 ifTrue:[
5052
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   328
        w1 := words first.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   329
        w2 := words second.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   330
        rslt := self classnameCompletion:w1 filter:filterBlock inEnvironment:anEnvironment.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   331
        bestMatch := rslt first.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   332
        matches := rslt second.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   333
        ('class' copyTo:(w2 size min:5)) = w2 ifTrue:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   334
            matches := matches collect:[:m | m , ' class'].
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   335
            bestMatch := bestMatch , ' class'.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   336
        ].
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   337
        ^ InputCompletionResult bestName:bestMatch matchingNames:matches
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
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
    (aPartialClassName startsWith:'Smalltalk::') ifTrue:[
5052
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   341
        nsPrefix := 'Smalltalk::'.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   342
        searchName := aPartialClassName withoutPrefix:'Smalltalk::'
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   343
    ] ifFalse:[
5052
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   344
        nsPrefix := ''.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   345
        searchName := aPartialClassName.
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   346
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   347
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   348
    searchName := searchName asUppercaseFirst.
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   349
    lcSearchName := searchName asLowercase.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   350
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   351
    isMatchString := searchName includesMatchCharacters.
5052
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   352
    (searchName size > 2 
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   353
        and:[ searchName first = $* 
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   354
        and:[ searchName last = $* ]]
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   355
    ) ifTrue:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   356
        isMatchString := false.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   357
        searchName := searchName unquote:$*.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   358
    ].
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   359
    
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   360
    searchName isEmpty ifTrue:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   361
        matches := Smalltalk allClassesForWhich:filterBlock.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   362
        ^ InputCompletionResult bestName:searchName matchingNames:#()
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   363
    ].
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   364
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   365
    matches := OrderedCollection new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   366
    matchedNamesWithoutPrefix := Set new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   367
    ignCaseMatches := OrderedCollection new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   368
    others := OrderedCollection new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   369
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   370
    tryToMatch :=
5052
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   371
        [:className :fullClassName|
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   372
            |addIt|
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   373
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   374
            isMatchString ifTrue:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   375
                addIt := searchName match:className
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   376
            ] ifFalse:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   377
                addIt := className includesString:searchName.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   378
            ].
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   379
            addIt ifTrue:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   380
                matches add:(nsPrefix , fullClassName).
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   381
                matchedNamesWithoutPrefix add:className.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   382
            ] ifFalse:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   383
                "/ try ignoring case
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   384
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   385
                isMatchString ifTrue:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   386
                    addIt := searchName match:className caseSensitive:false
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   387
                ] ifFalse:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   388
                    addIt := className includesString:lcSearchName caseSensitive:false.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   389
                    addIt ifFalse:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   390
                        others add:className
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   391
                    ]
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   392
                ].
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   393
                addIt ifTrue:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   394
                    ignCaseMatches add:(nsPrefix , fullClassName).
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   395
                    matchedNamesWithoutPrefix add:className.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   396
                ].
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   397
            ].
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   398
            addIt
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   399
        ].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   400
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   401
    anEnvironment allClassesForWhich:filterBlock do:[:aClass |
5052
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   402
        |addIt fullClassName classNameWithoutPrefix|
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   403
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   404
        aClass isMeta ifFalse:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   405
            fullClassName := aClass name.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   406
            classNameWithoutPrefix := aClass nameWithoutPrefix.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   407
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   408
            addIt := tryToMatch value:fullClassName value:fullClassName.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   409
            addIt ifFalse:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   410
                classNameWithoutPrefix ~~ fullClassName ifTrue:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   411
                    tryToMatch value:classNameWithoutPrefix value:fullClassName.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   412
                ].
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   413
            ].
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   414
        ]
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   415
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   416
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   417
"/    matches isEmpty ifTrue:[
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   418
"/        matches := ignCaseMatches.
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   419
"/    ].
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   420
    matches := matches , ignCaseMatches.
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   421
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   422
"/    matches isEmpty ifTrue:[
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   423
"/        matches := ignCaseMatches.
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   424
"/
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   425
"/"/    matches isEmpty ifTrue:[
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   426
"/"/        | nearBy |
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   427
"/"/        nearBy := SortedCollection new sortBlock:[:a :b | a key < b key].
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   428
"/"/        others do:[:className |
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   429
"/"/            |lcClassName dist cmpName|
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   430
"/"/
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   431
"/"/            lcClassName := className asLowercase.
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   432
"/"/            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
   433
"/"/
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   434
"/"/            cmpName := lcClassName copyTo:(lcSearchName size min:lcClassName size).
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   435
"/"/            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
   436
"/"/            cmpName := lcClassName copyTo:(lcSearchName size + 1 min:lcClassName size).
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   437
"/"/            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
   438
"/"/            dist < 4 ifTrue:[
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   439
"/"/                nearBy add:( dist -> (nsPrefix , className) ).
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   440
"/"/            ]
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   441
"/"/        ].
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   442
"/"/        matches := nearBy collect:[:eachPair | eachPair value].
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   443
"/"/    ].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   444
"/    ].
3876
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   445
6e63fce83590 fixed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   446
    matches isEmpty ifTrue:[
5052
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   447
        ^ InputCompletionResult bestName:searchName matchingNames:(Array with:searchName)
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   448
    ].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   449
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   450
    matches size == 1 ifTrue:[
5052
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   451
        best := matches first.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   452
        ^ 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
   453
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   454
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   455
    matches
5052
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   456
        sort:[:name1 :name2 |
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   457
            "name1 comes before:name2 iff"
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   458
            ((name2 includes:$:) and:[(name1 includes:$:) not])
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   459
            or:[ ((name1 includes:$:) == (name2 includes:$:))
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   460
                  and:[ (name1 size < name2 size)
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   461
                        or: [ name1 < name2 ]]
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   462
               ]
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   463
        ].
2661
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
    isMatchString ifTrue:[
5052
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   466
        best := searchName.
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   467
    ] ifFalse:[
5052
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   468
        matchesForLongestPrefix := matches select:[:m | m asLowercase startsWith:lcSearchName].
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   469
        best := ignCaseMatches isEmpty
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   470
                    ifTrue:[ matchesForLongestPrefix longestCommonPrefix ]
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   471
                    ifFalse:[ matchesForLongestPrefix longestCommonPrefixCaseSensitive:false ].
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   472
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   473
        best size < aPartialClassName size "best size == 0" ifTrue:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   474
            best := matchedNamesWithoutPrefix longestCommonPrefix.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   475
        ].
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   476
        best size == 0 ifTrue:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   477
            "if tried again, return next match"
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   478
            idx := ((matches indexOf:aPartialClassName) + 1) \\ matches size.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   479
            idx ~~ 1 ifTrue:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   480
                ^ InputCompletionResult bestName:(matches at:idx) matchingNames:(matches asArray)
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   481
            ].
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   482
        ].
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   483
        best size < aPartialClassName size ifTrue:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   484
            best := aPartialClassName.
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   485
        ].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   486
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   487
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   488
    cls := anEnvironment classNamed:best.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   489
    (cls isBehavior and:[cls isNameSpace]) ifTrue:[
5052
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   490
        (matches conform:[:each | each = best
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   491
                                 or:[each startsWith:(best , '::')]])
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   492
        ifTrue:[
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   493
            best := best , '::'
4df885d2b30f #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5051
diff changeset
   494
        ].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   495
    ].
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   496
    ^ 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
   497
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   498
    "
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   499
     Smalltalk classnameCompletion:'Arr'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   500
     Smalltalk classnameCompletion:'Arra'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   501
     Smalltalk classnameCompletion:'arra'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   502
     Smalltalk classnameCompletion:'*rray'
2661
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
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   505
    "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
   506
!
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   507
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   508
classnameCompletion:aPartialClassName inEnvironment:anEnvironment
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   509
    "given a partial classname, return an array consisting of
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   510
     2 entries: 1st: the best (longest) match
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   511
		2nd: collection consisting of matching names"
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   512
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   513
    ^ self
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   514
	classnameCompletion:aPartialClassName
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   515
	filter:[:cls | true]
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   516
	inEnvironment:anEnvironment
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   517
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   518
    "
4148
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   519
     self classnameCompletion:'Arr'   inEnvironment:Smalltalk
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   520
     self classnameCompletion:'Arra'  inEnvironment:Smalltalk
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   521
     self classnameCompletion:'arra'  inEnvironment:Smalltalk
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   522
     self classnameCompletion:'*rray' inEnvironment:Smalltalk
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   523
    "
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   524
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   525
    "Created: / 24-11-1995 / 17:24:45 / cg"
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   526
    "Modified: / 10-08-2006 / 13:01:30 / cg"
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   527
!
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   528
2977
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   529
entryCompletionBlockFor:completionSelector
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   530
    "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
   531
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   532
    ^ [:contents :field  |
5687
c5be8b9eff20 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5660
diff changeset
   533
          |s what m|
c5be8b9eff20 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5660
diff changeset
   534
c5be8b9eff20 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5660
diff changeset
   535
          s := contents withoutSpaces.
c5be8b9eff20 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5660
diff changeset
   536
          field topView withCursor:(Cursor questionMark) do:[
c5be8b9eff20 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5660
diff changeset
   537
              what := self perform:completionSelector with:s with:Smalltalk.
c5be8b9eff20 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5660
diff changeset
   538
          ].
c5be8b9eff20 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5660
diff changeset
   539
c5be8b9eff20 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5660
diff changeset
   540
          field contents:(what first).
c5be8b9eff20 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5660
diff changeset
   541
          (what at:2) size ~~ 1 ifTrue:[
c5be8b9eff20 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5660
diff changeset
   542
              field device beepInEditor
c5be8b9eff20 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5660
diff changeset
   543
          ]
2977
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   544
      ].
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   545
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   546
    "Created: / 10-08-2006 / 13:21:37 / cg"
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   547
!
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   548
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   549
globalNameCompletion:aPartialGlobalName inEnvironment:anEnvironment
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   550
    "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
   551
     2 entries: 1st: the best (longest) match
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   552
		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
   553
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   554
    ^ self globalNameCompletion:aPartialGlobalName inEnvironment:anEnvironment match:true
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   555
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   556
    "
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   557
     Smalltalk globalnameCompletion:'Arr'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   558
     Smalltalk globalnameCompletion:'Arra'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   559
     Smalltalk globalnameCompletion:'arra'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   560
     Smalltalk globalnameCompletion:'*rray'
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   561
    "
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   562
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   563
    "Created: / 10-08-2006 / 13:06:23 / cg"
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   564
!
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   565
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   566
globalNameCompletion:aPartialGlobalName inEnvironment:anEnvironment match:doMatch
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   567
    "given a partial globalName, return an array consisting of
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   568
     2 entries: 1st: the best (longest) match
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   569
		2nd: collection consisting of matching names"
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   570
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   571
    |searchName matches ignCaseMatches best isMatchString|
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   572
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   573
    searchName := aPartialGlobalName.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   574
    searchName isEmpty ifTrue:[
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   575
	^ Array with:searchName with:#()
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   576
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   577
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   578
    (searchName at:1) isLowercase ifTrue:[
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   579
	searchName := searchName copy asUppercaseFirst
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   580
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   581
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   582
    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
   583
    matches := OrderedCollection new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   584
    ignCaseMatches := OrderedCollection new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   585
    anEnvironment keysDo:[:aGlobalName |
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   586
	| addIt|
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   587
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   588
	isMatchString ifTrue:[
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   589
	    addIt := searchName match:aGlobalName
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   590
	] ifFalse:[
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   591
	    addIt := aGlobalName startsWith:searchName
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   592
	].
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   593
	addIt ifTrue:[
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   594
	    matches add:aGlobalName
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   595
	] ifFalse:[
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   596
	    "/ try ignoring case
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   597
	    isMatchString ifTrue:[
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   598
		addIt := searchName match:aGlobalName caseSensitive:false
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   599
	    ] ifFalse:[
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   600
		addIt := aGlobalName asLowercase startsWith:searchName asLowercase
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   601
	    ].
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   602
	    addIt ifTrue:[
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   603
		ignCaseMatches add:aGlobalName
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   604
	    ]
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   605
	]
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   606
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   607
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   608
    matches isEmpty ifTrue:[
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   609
	matches := ignCaseMatches
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   610
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   611
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   612
    matches isEmpty ifTrue:[
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   613
	^ 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
   614
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   615
    matches size == 1 ifTrue:[
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   616
	^ 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
   617
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   618
    matches := matches asSortedCollection.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   619
    isMatchString ifTrue:[
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   620
	best := searchName.
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   621
    ] ifFalse:[
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   622
	best := matches longestCommonPrefix.
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   623
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   624
    ^ 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
   625
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   626
    "
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   627
     Smalltalk globalnameCompletion:'Arr'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   628
     Smalltalk globalnameCompletion:'Arra'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   629
     Smalltalk globalnameCompletion:'arra'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   630
     Smalltalk globalnameCompletion:'*rray'
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   631
    "
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   632
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   633
    "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
   634
!
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   635
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   636
methodProtocolCompletion:aPartialProtocolName inEnvironment:anEnvironment
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   637
    "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
   638
     2 entries: 1st: the best (longest) match
6022
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   639
                2nd: collection consisting of matching protocols"
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   640
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   641
    |matches best lcName|
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   642
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   643
    matches := IdentitySet new.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   644
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   645
    "/ search for exact match
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   646
    anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
6022
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   647
        |protocol|
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   648
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   649
        protocol := eachMethod category.
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   650
        (protocol notNil and:[protocol startsWith:aPartialProtocolName]) ifTrue:[
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   651
            matches add:protocol
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   652
        ].
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   653
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   654
    matches isEmpty ifTrue:[
6022
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   655
        "/ search for case-ignoring match
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   656
        lcName := aPartialProtocolName asLowercase.
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   657
        anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   658
            |protocol|
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   659
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   660
            protocol := eachMethod category.
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   661
            (protocol notNil and:[protocol asLowercase startsWith:lcName]) ifTrue:[
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   662
                matches add:protocol
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   663
            ].
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   664
        ].
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   665
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   666
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   667
    matches isEmpty ifTrue:[
6022
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   668
        ^ Array with:aPartialProtocolName with:(Array with:aPartialProtocolName)
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   669
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   670
    matches size == 1 ifTrue:[
6022
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   671
        ^ Array with:matches first with:(matches asArray)
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   672
    ].
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   673
    matches := matches asSortedCollection.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   674
    best := matches longestCommonPrefix.
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   675
    ^ Array with:best with:matches asArray
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   676
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   677
    "
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   678
     Smalltalk methodProtocolCompletion:'doc'
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   679
     Smalltalk methodProtocolCompletion:'docu'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   680
     Smalltalk methodProtocolCompletion:'documenta'
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   681
    "
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   682
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   683
    "Created: / 10-08-2006 / 13:05:27 / cg"
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   684
    "Modified: / 16-03-2011 / 12:30:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
6022
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
   685
    "Modified: / 03-03-2019 / 22:43:07 / Claus Gittinger"
4051
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   686
!
fe8801e391cd moved extensions to base
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
   687
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   688
nameSpaceCompletion:aPartialClassName inEnvironment:anEnvironment
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   689
    "given a partial name, return an array consisting of
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   690
     2 entries: 1st: the best (longest) match
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   691
		2nd: collection consisting of matching names"
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   692
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   693
    ^ self
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   694
	classnameCompletion:aPartialClassName
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   695
	filter:[:cls | cls isNameSpace]
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   696
	inEnvironment:anEnvironment
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   697
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   698
    "
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   699
     DoWhatIMeanSupport nameSpaceCompletion:'To'  inEnvironment:Smalltalk
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   700
    "
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   701
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   702
    "Created: / 10-08-2006 / 13:02:16 / cg"
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   703
!
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   704
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   705
packageCompletion:aPartialPackage inEnvironment:anEnvironment
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   706
    "given a partial package name, return an array consisting of
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   707
     2 entries: 1st: the best (longest) match
4976
2e6c19f32c49 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
   708
                2nd: collection consisting of matching packages"
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   709
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   710
    |matches best lcName|
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   711
4976
2e6c19f32c49 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
   712
    matches := Smalltalk allPackageIDs
2e6c19f32c49 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
   713
        select:[:package | package startsWith:aPartialPackage].
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   714
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   715
    matches isEmpty ifTrue:[
4976
2e6c19f32c49 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
   716
        "/ search for case-ignoring match
2e6c19f32c49 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
   717
        lcName := aPartialPackage asLowercase.
2e6c19f32c49 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
   718
        anEnvironment allClassesDo:[:aClass |
2e6c19f32c49 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
   719
            |package|
2e6c19f32c49 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
   720
2e6c19f32c49 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
   721
            package := aClass package.
2e6c19f32c49 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
   722
            (package notNil and:[package asLowercase startsWith:lcName]) ifTrue:[
2e6c19f32c49 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
   723
                matches add:package
2e6c19f32c49 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
   724
            ].
2e6c19f32c49 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
   725
        ].
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   726
    ].
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   727
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   728
    matches isEmpty ifTrue:[
4976
2e6c19f32c49 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
   729
        ^ Array with:aPartialPackage with:(Array with:aPartialPackage)
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   730
    ].
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   731
    matches size == 1 ifTrue:[
4976
2e6c19f32c49 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
   732
        ^ Array with:matches first with:(matches asArray)
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   733
    ].
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   734
    matches := matches asSortedCollection.
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   735
    best := matches longestCommonPrefix.
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   736
    ^ Array with:best with:matches asArray
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   737
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   738
    "
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   739
     DoWhatIMeanSupport packageCompletion:'stx:' inEnvironment:Smalltalk
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   740
     DoWhatIMeanSupport packageCompletion:'stx:libw' inEnvironment:Smalltalk
2975
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   741
    "
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   742
300462273a16 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   743
    "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
   744
!
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   745
2977
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   746
packageNameEntryCompletionBlock
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   747
    "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
   748
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   749
    ^ self entryCompletionBlockFor:#'packageCompletion:inEnvironment:'
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   750
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   751
    "Created: / 10-08-2006 / 13:22:31 / cg"
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   752
!
3e4b5adccfd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2975
diff changeset
   753
4148
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   754
poolnameCompletion:aPartialClassName inEnvironment:anEnvironment
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   755
    "given a partial poolname, return an array consisting of
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   756
     2 entries: 1st: the best (longest) match
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   757
		2nd: collection consisting of matching names"
4148
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   758
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   759
    ^ self
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   760
	classnameCompletion:aPartialClassName
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   761
	filter:[:cls | cls isSharedPool]
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   762
	inEnvironment:anEnvironment
4148
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   763
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   764
    "
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   765
     self poolnameCompletion:'Win' inEnvironment:Smalltalk
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   766
     self poolnameCompletion:'Z'   inEnvironment:Smalltalk
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   767
     self poolnameCompletion:'a'   inEnvironment:Smalltalk
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   768
    "
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   769
!
b314d59c1654 added: #poolnameCompletion:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 4146
diff changeset
   770
4049
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   771
resourceCompletion:aPartialResourceName inEnvironment:anEnvironment match:doMatch ignoreCase:ignoreCase
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   772
    "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
   773
     2 entries: 1st: the longest match
5713
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   774
                2nd: collection consisting of matching defined resources"
4049
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   775
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   776
    |matches best lcSym isMatch|
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   777
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   778
    matches := IdentitySet new.
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   779
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   780
    isMatch := doMatch and:[aPartialResourceName includesMatchCharacters].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   781
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   782
    anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
5713
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   783
        eachMethod hasResource ifTrue:[
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   784
            eachMethod resources keysDo:[:eachResourceName |
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   785
                |addToMatches|
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   786
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   787
                isMatch ifTrue:[ 
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   788
                    addToMatches := aPartialResourceName match:eachResourceName caseSensitive:ignoreCase not 
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   789
                ] ifFalse:[ 
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   790
                    ignoreCase ifTrue:[ 
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   791
                        addToMatches := eachResourceName asLowercase startsWith:aPartialResourceName asLowercase 
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   792
                    ] ifFalse:[ 
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   793
                        addToMatches := eachResourceName startsWith:aPartialResourceName 
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   794
                    ] 
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   795
                ].
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   796
                addToMatches ifTrue:[
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   797
                    matches add:eachResourceName
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   798
                ].
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   799
            ].
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   800
        ].
4049
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   801
    ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   802
    (matches isEmpty and:[ignoreCase not]) ifTrue:[
5713
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   803
        "/ search for case-ignoring match
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   804
        lcSym := aPartialResourceName asLowercase.
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   805
        anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   806
            eachMethod hasResource ifTrue:[
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   807
                eachMethod resources keysDo:[:eachResourceName |
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   808
                    |addToMatches|
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   809
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   810
                    isMatch ifTrue:[ 
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   811
                        addToMatches := aPartialResourceName match:eachResourceName caseSensitive:false 
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   812
                    ] ifFalse:[ 
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   813
                        addToMatches := eachResourceName asLowercase startsWith:lcSym 
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   814
                    ].
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   815
                    addToMatches ifTrue:[
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   816
                        matches add:eachResourceName
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   817
                    ].
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   818
                ].
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   819
            ].
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   820
        ].
4049
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   821
    ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   822
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   823
    matches isEmpty ifTrue:[
5713
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   824
        ^ Array with:aPartialResourceName with:#()
4049
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   825
    ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   826
    matches size == 1 ifTrue:[
5713
c07c5d59bbff #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5706
diff changeset
   827
        ^ Array with:matches first with:(matches asArray)
4049
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   828
    ].
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   829
    matches := matches asSortedCollection.
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   830
    best := matches longestCommonPrefix.
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   831
    ^ Array with:best with:matches asArray
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   832
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   833
    "
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   834
     DoWhatIMeanSupport resourceCompletion:'*debug*' inEnvironment:Smalltalk match:true ignoreCase:false
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   835
     DoWhatIMeanSupport resourceCompletion:'context' inEnvironment:Smalltalk match:true ignoreCase:false
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   836
     DoWhatIMeanSupport resourceCompletion:'key' inEnvironment:Smalltalk match:true ignoreCase:false
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   837
     DoWhatIMeanSupport resourceCompletion:'cont' inEnvironment:Smalltalk match:true ignoreCase:false
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   838
    "
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   839
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   840
    "Created: / 06-07-2011 / 12:04:41 / cg"
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   841
!
b5540a857436 added: #resourceCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 4047
diff changeset
   842
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   843
selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   844
    "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
   845
     2 entries: 1st: the longest match
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   846
		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
   847
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   848
    ^ self selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment match:false
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   849
!
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   850
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   851
selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment match:doMatch
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   852
    "given a partial selector, return an array consisting of
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   853
     2 entries: 1st: the longest match
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   854
		2nd: collection consisting of matching implemented selectors"
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   855
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   856
    ^ self
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   857
	selectorCompletion:aPartialSymbolName
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   858
	inEnvironment:anEnvironment
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   859
	match:doMatch
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
   860
	ignoreCase:false
3955
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   861
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   862
    "
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   863
     DoWhatIMeanSupport selectorCompletion:'inst*p' inEnvironment:Smalltalk match:true
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   864
     DoWhatIMeanSupport selectorCompletion:'inst*pl' inEnvironment:Smalltalk match:true
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   865
     DoWhatIMeanSupport selectorCompletion:'at:p' inEnvironment:Smalltalk match:true
3955
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   866
     DoWhatIMeanSupport selectorCompletion:'nextP' inEnvironment:Smalltalk match:true
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   867
     DoWhatIMeanSupport selectorCompletion:'nextp' inEnvironment:Smalltalk match:true
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   868
    "
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   869
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   870
    "Modified: / 07-06-1996 / 08:44:33 / stefan"
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   871
    "Modified: / 26-10-2010 / 20:30:27 / cg"
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   872
!
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   873
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   874
selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment match:doMatch ignoreCase:ignoreCase
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   875
    "given a partial selector, return an array consisting of
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   876
     2 entries: 1st: the longest match
5714
043564e0ae20 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5713
diff changeset
   877
                2nd: collection consisting of matching implemented selectors"
3955
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   878
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   879
    |matches best lcSym isMatch|
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   880
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   881
    matches := IdentitySet new.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   882
3863
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   883
    isMatch := doMatch and:[aPartialSymbolName includesMatchCharacters].
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
   884
3751
eafbe64ab0fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
   885
    anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
5714
043564e0ae20 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5713
diff changeset
   886
        |addToMatches|
043564e0ae20 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5713
diff changeset
   887
043564e0ae20 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5713
diff changeset
   888
        isMatch ifTrue:[ 
043564e0ae20 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5713
diff changeset
   889
            addToMatches := (aPartialSymbolName match:eachSelector caseSensitive:ignoreCase not) 
043564e0ae20 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5713
diff changeset
   890
        ] ifFalse:[ 
043564e0ae20 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5713
diff changeset
   891
            ignoreCase ifTrue:[ 
043564e0ae20 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5713
diff changeset
   892
                addToMatches := (eachSelector asLowercase startsWith:aPartialSymbolName asLowercase) 
043564e0ae20 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5713
diff changeset
   893
            ] ifFalse:[ 
043564e0ae20 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5713
diff changeset
   894
                addToMatches := (eachSelector startsWith:aPartialSymbolName) 
043564e0ae20 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5713
diff changeset
   895
            ] 
043564e0ae20 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5713
diff changeset
   896
        ].
043564e0ae20 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5713
diff changeset
   897
        addToMatches ifTrue:[
043564e0ae20 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5713
diff changeset
   898
            matches add:eachSelector
043564e0ae20 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5713
diff changeset
   899
        ].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   900
    ].
3955
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   901
    (matches isEmpty and:[ignoreCase not]) ifTrue:[
5714
043564e0ae20 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5713
diff changeset
   902
        "/ search for case-ignoring match
043564e0ae20 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5713
diff changeset
   903
        lcSym := aPartialSymbolName asLowercase.
043564e0ae20 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5713
diff changeset
   904
        anEnvironment allMethodsWithSelectorDo:[:eachMethod :eachSelector |
043564e0ae20 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5713
diff changeset
   905
            |addToMatches|
043564e0ae20 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5713
diff changeset
   906
043564e0ae20 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5713
diff changeset
   907
            isMatch ifTrue:[ 
043564e0ae20 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5713
diff changeset
   908
                addToMatches := (aPartialSymbolName match:eachSelector caseSensitive:false) 
043564e0ae20 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5713
diff changeset
   909
            ] ifFalse:[ 
043564e0ae20 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5713
diff changeset
   910
                addToMatches := (eachSelector asLowercase startsWith:lcSym) 
043564e0ae20 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5713
diff changeset
   911
            ].
043564e0ae20 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5713
diff changeset
   912
            addToMatches ifTrue:[
043564e0ae20 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5713
diff changeset
   913
                matches add:eachSelector
043564e0ae20 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5713
diff changeset
   914
            ].
043564e0ae20 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5713
diff changeset
   915
        ].
2661
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   916
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   917
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   918
    matches isEmpty ifTrue:[
5714
043564e0ae20 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5713
diff changeset
   919
        ^ 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
   920
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   921
    matches size == 1 ifTrue:[
5714
043564e0ae20 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5713
diff changeset
   922
        ^ 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
   923
    ].
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   924
    matches := matches asSortedCollection.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   925
    best := matches longestCommonPrefix.
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   926
    ^ 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
   927
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   928
    "
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   929
     DoWhatIMeanSupport selectorCompletion:'inst*p' inEnvironment:Smalltalk match:true
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   930
     DoWhatIMeanSupport selectorCompletion:'inst*pl' inEnvironment:Smalltalk match:true
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
   931
     DoWhatIMeanSupport selectorCompletion:'at:p' inEnvironment:Smalltalk match:true
3867
03f7ad841731 changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
   932
     DoWhatIMeanSupport selectorCompletion:'nextP' inEnvironment:Smalltalk match:true
03f7ad841731 changed: #selectorCompletion:inEnvironment:match:
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
   933
     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
   934
    "
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   935
3955
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   936
    "Modified: / 07-06-1996 / 08:44:33 / stefan"
94fb4a47d108 added: #selectorCompletion:inEnvironment:match:ignoreCase:
Claus Gittinger <cg@exept.de>
parents: 3929
diff changeset
   937
    "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
   938
! !
f68913f2facf moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   939
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   940
!DoWhatIMeanSupport class methodsFor:'rename support'!
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   941
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   942
goodRenameDefaultFor:oldName lastOld:lastOldName lastNew:lastNewName
2513
de7a2f5335c2 comments
Claus Gittinger <cg@exept.de>
parents: 2468
diff changeset
   943
    "generate a reasonable default for a rename operation.
de7a2f5335c2 comments
Claus Gittinger <cg@exept.de>
parents: 2468
diff changeset
   944
     (used for rename category etc.)"
2468
beeedb5f57f4 comment
Claus Gittinger <cg@exept.de>
parents: 2434
diff changeset
   945
4065
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
   946
    |prefix suffix lastNewSize lastOldSize left right inserted deleted tryAgain|
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   947
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   948
    lastNewName isNil ifTrue:[ ^ nil].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   949
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   950
    lastNewSize := lastNewName size.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   951
    lastOldSize := lastOldName size.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   952
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   953
    (lastNewName endsWith:lastOldName) ifTrue:[
5143
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   954
        "last rename was
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   955
            'foo' -> 'Xfoo'
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   956
         then, a good default for
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   957
            'bar' would be 'Xbar'
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   958
        "
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   959
        prefix := lastNewName copyTo:(lastNewSize - lastOldSize).
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   960
        ^ (prefix , oldName).
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   961
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   962
    (lastOldName endsWith:lastNewName) ifTrue:[
5143
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   963
        "last rename was
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   964
            'Xfoo' -> 'foo'
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   965
         then, a good default for
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   966
            'Xbar' would be 'bar'
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   967
        "
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   968
        prefix := lastOldName copyTo:(lastOldSize - lastNewSize).
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   969
        (oldName startsWith:prefix) ifTrue:[
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   970
            ^ (oldName copyFrom:prefix size+1).
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   971
        ]
2514
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   972
    ].
4f8d8658289a comments
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   973
    (lastOldName asLowercase = lastNewName asLowercase) ifTrue:[
5143
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   974
        (lastOldName first ~= lastNewName first) ifTrue:[
5552
2fe0fa28ecf5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5551
diff changeset
   975
            (lastOldName isLowercaseFirst = oldName isLowercaseFirst) ifTrue:[
5143
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   976
                "last rename was
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   977
                    'xfoo' -> 'Xfoo'
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   978
                 then, a good default for
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   979
                    'xbar' would be 'Xbar'
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   980
                "
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   981
                lastOldName first isLowercase ifTrue:[
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   982
                    ^ oldName asUppercaseFirst "oldName first asUppercase asString , (oldName copyFrom:2)".
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   983
                ] ifFalse:[
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   984
                    ^ oldName asLowercaseFirst "oldName first asLowercase asString , (oldName copyFrom:2)".
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   985
                ]
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   986
            ]
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   987
        ].
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   988
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   989
    (lastOldName withoutSeparators = lastNewName) ifTrue:[
5143
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   990
        "last rename was
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   991
            '  foo   ' -> 'foo'
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   992
         then, a good default for
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   993
            '  bar   ' would be 'bar'
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   994
        "
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   995
        ^ oldName withoutSeparators.
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   996
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   997
    (lastNewName startsWith:lastOldName) ifTrue:[
5143
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   998
        "last rename was
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
   999
            'foo' -> 'fooX'
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1000
         then, a good default for
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1001
            'bar' would be 'barX'
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1002
        "
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1003
        suffix := lastNewName copyLast:(lastNewSize - lastOldSize).
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1004
        ^ (oldName , suffix).
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1005
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1006
    (lastOldName startsWith:lastNewName) ifTrue:[
5143
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1007
        "last rename was
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1008
            'fooX' -> 'foo'
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1009
         then, a good default for
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1010
            'barX' would be 'bar'
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1011
        "
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1012
        suffix := lastOldName copyLast:(lastOldSize - lastNewSize).
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1013
        (oldName endsWith:suffix) ifTrue:[
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1014
            ^ (oldName copyButLast:suffix size).
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1015
        ]
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1016
    ].
2558
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  1017
2557
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
  1018
    prefix := lastOldName commonPrefixWith:lastNewName.
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
  1019
    suffix := lastOldName commonSuffixWith:lastNewName.
2559
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
  1020
6013
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1021
    (prefix size ~~ 0) ifTrue:[
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1022
        (suffix size ~~ 0) ifTrue:[
5143
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1023
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1024
            prefix := prefix copyTo:(((lastNewName size - suffix size) min:(lastOldName size - suffix size)) min:prefix size).
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1025
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1026
            "last rename was
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1027
                'fooR' -> 'fooXR'
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1028
             then, a good default for
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1029
                'barR' would be 'barXR'
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1030
            "
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1031
            left := lastOldName copyTo:prefix size.
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1032
            right := lastOldName copyLast:suffix size.
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1033
            lastNewSize > lastOldSize ifTrue:[
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1034
                inserted := (lastNewName copyFrom:(left size + 1)) copyButLast:(right size).
6013
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1035
                inserted size ~~ 0 ifTrue:[
5143
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1036
                    (oldName startsWith:prefix) ifTrue:[
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1037
                        ^ oldName copyWithAll:inserted insertedAfterIndex:prefix size
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1038
                    ].
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1039
                ].
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1040
            ].
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1041
            (oldName string endsWith:suffix string) ifTrue:[
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1042
                deleted := (lastOldName string copyFrom:(prefix size + 1)) copyButLast:(suffix size).
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1043
                (oldName size-suffix size-deleted size + 1) >= 1 ifTrue:[
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1044
                    ((oldName copyFrom:oldName size-suffix size-deleted size + 1) copyTo:deleted size) = deleted ifTrue:[
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1045
                        "last rename was
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1046
                            'fooXR' -> 'fooR'
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1047
                         then, a good default for
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1048
                            'barXS' would be 'barS'
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1049
                        "
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1050
                        ^ (oldName copyTo:oldName size-suffix size-deleted size) , suffix
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1051
                    ]
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1052
                ]
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1053
            ]
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1054
        ].
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1055
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1056
        (oldName endsWith:(lastOldName copyFrom:prefix size+1)) ifTrue:[
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1057
            "last rename was
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1058
                'fooX' -> 'fooY'
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1059
             then, a good default for
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1060
                'barX' would be 'barY'
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1061
            "
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1062
            left := oldName copyButLast:(lastOldName copyFrom:prefix size+1) size.
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1063
            right := lastNewName copyFrom:prefix size+1.
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1064
            ^ left , right
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1065
        ]
2557
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
  1066
    ].
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1067
6013
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1068
    suffix size ~~ 0 ifTrue:[
5143
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1069
        |prefix2|
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1070
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1071
        "last rename was:
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1072
            'fooSUFF1' -> 'barSUFF1'
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1073
         then, a good default for
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1074
            'fooSUFF2' -> 'barSUFF2'
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1075
        "
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1076
        prefix := lastOldName copyTo:(lastOldName size - suffix size).  "/ the foo
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1077
        (oldName startsWith:prefix) ifTrue:[
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1078
            prefix2 := lastNewName copyTo:(lastNewName size - suffix size). "/ the bar
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1079
            ^ prefix2,(oldName copyFrom:(prefix size+1)).
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1080
        ].
4065
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  1081
    ].
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  1082
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  1083
    "/ was there something stripped at the end?
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1084
    suffix := oldName commonSuffixWith:lastOldName.
6013
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1085
    (suffix size ~~ 0) ifTrue:[
5143
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1086
        ^ self
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1087
            goodRenameDefaultFor:(oldName copyButLast:suffix size)
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1088
            lastOld:(lastOldName copyButLast:suffix size)
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1089
            lastNew:lastNewName.
4065
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  1090
    ].
2382
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
  1091
    ^ nil
2557
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
  1092
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
  1093
    "
2558
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  1094
     self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'fooXX'
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  1095
     self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'XXfoo'
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  1096
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1097
     self goodRenameDefaultFor:'barXX' lastOld:'fooXX' lastNew:'foo'
2558
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  1098
     self goodRenameDefaultFor:'XXbar' lastOld:'XXfoo' lastNew:'foo'
81ef3253fd23 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2557
diff changeset
  1099
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1100
     self goodRenameDefaultFor:'barXX' lastOld:'fooXX' lastNew:'fooYY'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1101
     self goodRenameDefaultFor:'XXbar' lastOld:'XXfoo' lastNew:'foo'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1102
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1103
     self goodRenameDefaultFor:'bar2' lastOld:'foo1' lastNew:'foo01'
2559
f9f489baf23f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2558
diff changeset
  1104
     self goodRenameDefaultFor:'barXY' lastOld:'fooXY' lastNew:'fooY'
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1105
     self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'fXoo'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1106
     self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'fXXXoo'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1107
     self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'foXXXo'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1108
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1109
     self goodRenameDefaultFor:'bar001' lastOld:'foo001' lastNew:'foo002_001'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1110
     self goodRenameDefaultFor:'CoastCore-CSFoo' lastOld:'CoastCore-CSBar' lastNew:'Coast-Core-CSBar'
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1111
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1112
     self goodRenameDefaultFor:'mti.odt2.level1HeadlineStyle'
5143
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1113
                       lastOld:'mti.odt2.level1HeadlineMatchPattern'
0162f8ec658a #OTHER by mawalch
mawalch
parents: 5133
diff changeset
  1114
                       lastNew:'Key_odt2_level1HeadlineMatchPattern'
2557
b1d8a61319d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2553
diff changeset
  1115
    "
4065
ebea28fa8bab changed: #goodRenameDefaultFor:lastOld:lastNew:
Claus Gittinger <cg@exept.de>
parents: 4058
diff changeset
  1116
5552
2fe0fa28ecf5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5551
diff changeset
  1117
    "Modified: / 22-06-2017 / 06:56:55 / cg"
6013
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1118
    "Modified: / 01-03-2019 / 14:53:49 / Claus Gittinger"
2382
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
  1119
!
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
  1120
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
  1121
goodRenameDefaultForFile:oldName lastOld:lastOldName lastNew:lastNewName
2513
de7a2f5335c2 comments
Claus Gittinger <cg@exept.de>
parents: 2468
diff changeset
  1122
    "generate a reasonable default for a file rename operation.
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1123
     (Try to rename multiple files in the new fileBrowser,
2513
de7a2f5335c2 comments
Claus Gittinger <cg@exept.de>
parents: 2468
diff changeset
  1124
     to see what this is doing)"
2468
beeedb5f57f4 comment
Claus Gittinger <cg@exept.de>
parents: 2434
diff changeset
  1125
2382
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
  1126
    |prefix suffix t
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
  1127
     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
  1128
     lastRemoved lastInserted default|
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
  1129
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
  1130
    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
  1131
    default notNil ifTrue:[ ^ default].
d89d86edaae4 separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents: 2376
diff changeset
  1132
3135
7ad9ff29225e changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents: 2977
diff changeset
  1133
    lastOldWOSuffix := lastOldName asFilename nameWithoutSuffix.
7ad9ff29225e changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents: 2977
diff changeset
  1134
    lastNewWOSuffix := lastNewName asFilename nameWithoutSuffix.
7ad9ff29225e changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents: 2977
diff changeset
  1135
    oldWOSuffix := oldName asFilename nameWithoutSuffix.
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1136
2434
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
  1137
    "/ suffix change ?
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
  1138
    lastOldWOSuffix = lastNewWOSuffix ifTrue:[
6013
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1139
        lastOldName asFilename suffix ~= lastNewName asFilename suffix ifTrue:[
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1140
            ^ (oldName asFilename withSuffix:(lastNewName asFilename suffix)) pathName
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1141
        ].
2434
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
  1142
    ].
e7758915432e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2382
diff changeset
  1143
2553
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
  1144
    default := self goodRenameDefaultFor:oldWOSuffix lastOld:lastOldWOSuffix lastNew:lastNewWOSuffix.
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1145
    default notNil ifTrue:[
6013
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1146
        lastOldRest := lastOldName copyFrom:lastOldWOSuffix size + 1.
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1147
        lastNewRest := lastNewName copyFrom:lastNewWOSuffix size + 1.
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1148
        oldRest := oldName copyFrom:oldWOSuffix size + 1.
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1149
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1150
        ^ default , lastNewRest
2553
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
  1151
    ].
9925f0aca022 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
  1152
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1153
    prefix := lastOldWOSuffix commonPrefixWith:oldWOSuffix.
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1154
    (lastNewWOSuffix startsWith:prefix) ifTrue:[
6013
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1155
        lastOldRest := lastOldWOSuffix copyFrom:prefix size + 1.
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1156
        lastNewRest := lastNewWOSuffix copyFrom:prefix size + 1.
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1157
        oldRest := oldWOSuffix copyFrom:prefix size + 1.
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1158
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1159
        (lastNewRest endsWith:lastOldRest) ifTrue:[
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1160
            t := lastNewRest copyButLast:lastOldRest size.
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1161
            ^ ((prefix , t , oldRest) asFilename withSuffix:oldName asFilename suffix) name
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1162
        ].
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1163
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1164
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1165
    suffix := lastOldWOSuffix commonSuffixWith:lastNewWOSuffix.
6013
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1166
    suffix size ~~ 0 ifTrue:[
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1167
        "/ last change changed something at the beginning
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1168
        prefix := oldWOSuffix commonPrefixWith:lastOldWOSuffix.
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1169
        prefix size ~~ 0 ifTrue:[
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1170
            "/ this name starts with the same characters
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1171
            lastRemoved := lastOldWOSuffix copyButLast:suffix size.
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1172
            lastInserted := lastNewWOSuffix copyButLast:suffix size.
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1173
            (lastRemoved startsWith:lastInserted) ifTrue:[
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1174
                oldWOSuffix size >= lastInserted size ifTrue:[
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1175
                    ^ (oldWOSuffix copyTo:lastInserted size) , (oldName copyFrom:lastRemoved size + 1)
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1176
                ]
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1177
            ].
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1178
            ^ lastInserted , (oldName copyFrom:lastRemoved size + 1)
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1179
        ].
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1180
    ].
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1181
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1182
    ^ nil
3135
7ad9ff29225e changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents: 2977
diff changeset
  1183
7ad9ff29225e changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents: 2977
diff changeset
  1184
    "Modified: / 07-11-2006 / 13:58:39 / cg"
6013
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  1185
    "Modified: / 01-03-2019 / 14:53:36 / Claus Gittinger"
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1186
! !
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1187
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1188
!DoWhatIMeanSupport class methodsFor:'typing distance'!
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1189
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1190
isKey:k1 nextTo:k2
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  1191
    "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
  1192
     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
  1193
     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
  1194
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1195
    ^ 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
  1196
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1197
    "
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1198
     self isKey:$a nextTo:$a
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1199
     self isKey:$a nextTo:$s
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1200
     self isKey:$a nextTo:$q
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1201
     self isKey:$a nextTo:$w
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1202
     self isKey:$a nextTo:$z
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1203
     self isKey:$a nextTo:$x
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1204
    "
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1205
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1206
    "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
  1207
!
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1208
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1209
isKey:k1 nextTo:k2 onKeyboard:keys
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1210
    "return true, if k1 and k2 are adjacent keys on the keyboard defined by keys.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1211
     This is used to specially priorize plausible typing errors of adjacent keys.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1212
     (typo checker uses a modified levenshtein, 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1213
      in which keys next to each other are valued differently)"
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1214
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1215
    |row1 row2 col1 col2|
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1216
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  1217
    row1 := keys findFirst:[:eachRow | col1 := eachRow indexOf:k1. col1 ~~ 0].
2517
a5323c17b767 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2516
diff changeset
  1218
    row1 == 0 ifTrue:[^ false].
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  1219
    row2 := keys findFirst:[:eachRow | col2 := eachRow indexOf:k2. col2 ~~ 0].
2517
a5323c17b767 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2516
diff changeset
  1220
    row2 == 0 ifTrue:[^ false].
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1221
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  1222
    ^ (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
  1223
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1224
    "
2774
82e1d84243f4 comment
Stefan Vogel <sv@exept.de>
parents: 2667
diff changeset
  1225
     self isKey:$a nextTo:$q
2517
a5323c17b767 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2516
diff changeset
  1226
     self isKey:$a nextTo:$x
2515
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1227
    "
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1228
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  1229
    "Modified (comment): / 01-05-2016 / 12:19:24 / cg"
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1230
!
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1231
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1232
keyboard
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1233
    "the keyboard layout
4386
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1234
     (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
  1235
     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
  1236
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1237
    |lang|
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1238
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1239
    lang := UserPreferences current language.
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1240
    lang == #de ifTrue:[
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1241
	^ #(
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1242
	       '1234567890-'
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1243
	       '*qwertzuiop'
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1244
	       '**asdfghjkl:'
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1245
	       '***yxcvbnm'
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1246
	).
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1247
    ].
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1248
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1249
    lang == #fr ifTrue:[
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1250
	^ #(
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1251
	       '1234567890'
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1252
	       '*azertyuiop'
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1253
	       '**qsdfghjklm'
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1254
	       '***wxcvbn,'
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1255
	).
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1256
    ].
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1257
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1258
    ^ #(
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1259
	   '1234567890-'
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1260
	   '*qwertyuiop'
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1261
	   '**asdfghjkl:'
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1262
	   '***zxcvbnm'
4386
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  1263
    ).
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1264
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1265
    "
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1266
     self keyboard
3316
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1267
    "
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1268
745c8130b3a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3310
diff changeset
  1269
    "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
  1270
! !
69cbb89c127e +isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents: 2514
diff changeset
  1271
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1272
!DoWhatIMeanSupport methodsFor:'code completion'!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1273
4426
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1274
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
  1275
    "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
  1276
     (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
  1277
     the info as argument. 
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1278
     The interface has been defined in that way 
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1279
     (and tight coupling with internals of the editor) because
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1280
        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
  1281
        2) the edit operation for completion may be non-trivial
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1282
           (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
  1283
     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
  1284
     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
  1285
     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
  1286
     perform the completion.
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1287
     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
  1288
     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
  1289
     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
  1290
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1291
     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
  1292
     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
  1293
     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
  1294
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1295
    | language |
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1296
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1297
    codeAspect := codeAspectArg.
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1298
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1299
    languageOrNilArg notNil ifTrue:[
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1300
        language := languageOrNilArg
4426
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1301
    ] ifFalse:[
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1302
        contextOrNilArg notNil ifTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1303
            | method |
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1304
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1305
            method := contextOrNilArg method.
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1306
            method notNil ifTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1307
                language := method programmingLanguage
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1308
            ] ifFalse:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1309
                contextOrNilArg isJavaContext ifTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1310
                    language := JavaLanguage instance
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1311
                ] ifFalse:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1312
                    language := SmalltalkLanguage instance.
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1313
                ].
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1314
            ].
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1315
        ] ifFalse:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1316
            methodOrNilArg notNil ifTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1317
                language := methodOrNilArg programmingLanguage
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1318
            ] ifFalse:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1319
                classOrNilArg notNil ifTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1320
                    language := classOrNilArg programmingLanguage
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1321
                ]
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1322
            ]
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1323
        ].
4426
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1324
    ].
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1325
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1326
    language notNil ifTrue:[
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1327
        language isSmalltalk ifTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1328
            ^self codeCompletionForSmalltalkMethod: methodOrNilArg orClass: classOrNilArg context: contextOrNilArg codeView: codeViewArg into: actionBlock
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1329
        ].
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1330
        language isSTXJavaScript ifTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1331
            ^self codeCompletionForJavascriptMethod: methodOrNilArg orClass: classOrNilArg context: contextOrNilArg codeView: codeViewArg into: actionBlock
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1332
        ].
4426
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1333
    ].
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1334
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1335
    "/ No completion support for given language
5051
6e150dbaf9bc #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 5050
diff changeset
  1336
    "/ self breakPoint: #cg.
4426
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1337
    self breakPoint: #jv.
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1338
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1339
    "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
  1340
    "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
  1341
!
76a0c105e8f4 Updated to take codeAspect as an argument for completion.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4423
diff changeset
  1342
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1343
codeCompletionForLanguage: languageOrNil class: classOrNilArg context:contextOrNilArg codeView:codeViewArg
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  1344
    "going to become OBSOLETE; migrating to use the the new 'xxx: into:' protocol.
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1345
     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
  1346
     nil, if called from the browser.
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1347
     If nonNil, we can make better guesses, 
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1348
     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
  1349
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1350
    | language |
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1351
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1352
    languageOrNil notNil ifTrue:[
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1353
        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
  1354
    ] ifFalse:[
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1355
        contextOrNilArg notNil ifTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1356
            language := contextOrNilArg method programmingLanguage.
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1357
        ] ifFalse:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1358
            classOrNilArg notNil ifTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1359
                language := classOrNilArg programmingLanguage.
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1360
            ]
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1361
        ].
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1362
    ].
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1363
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1364
    language notNil ifTrue:[
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1365
        language isSmalltalk ifTrue:[
4731
145b177a3203 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4727
diff changeset
  1366
            classOrNil := classOrNilArg.
145b177a3203 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4727
diff changeset
  1367
            contextOrNil := contextOrNilArg.
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1368
            ^self codeCompletionForSmalltalkClass: classOrNil context: contextOrNil codeView: codeViewArg
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1369
        ].
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1370
    ].
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1371
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1372
    "/ 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
  1373
    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
  1374
    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
  1375
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1376
    "Created: / 18-09-2013 / 13:49:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
5007
045024ffa956 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4976
diff changeset
  1377
!
045024ffa956 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4976
diff changeset
  1378
045024ffa956 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4976
diff changeset
  1379
setClass: classOrNilArg andContext:contextOrNilArg
045024ffa956 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4976
diff changeset
  1380
    classOrNil := classOrNilArg.
045024ffa956 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4976
diff changeset
  1381
    contextOrNil := contextOrNilArg.
5272
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
  1382
!
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
  1383
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
  1384
setSelf: instanceOrNilArg 
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
  1385
    instanceOrNil := instanceOrNilArg.
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1386
! !
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1387
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1388
!DoWhatIMeanSupport methodsFor:'code completion - JavaScript'!
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1389
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1390
codeCompletionForJavascriptMethod:methodOrNilArg orClass:classOrNilArg context:contextOrNilArg codeView:codeViewArg into:actionBlock
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1391
    "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
  1392
     (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
  1393
     the info as argument. 
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1394
     The interface has been defined in that way 
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1395
     (and tight coupling with internals of the editor) because
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1396
        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
  1397
        2) the edit operation for completion may be non-trivial
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1398
           (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
  1399
     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
  1400
     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
  1401
     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
  1402
     perform the completion.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1403
     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
  1404
     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
  1405
     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
  1406
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1407
     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
  1408
     or nil, if called from the browser.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1409
     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
  1410
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1411
    languageOrNil := STXJavaScriptLanguage instance.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1412
    methodOrNil := methodOrNilArg.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1413
    classOrNil := classOrNilArg.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1414
    codeView := codeViewArg.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1415
    contextOrNil := contextOrNilArg.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1416
4423
c21baefab5d0 Call to JavaScriptCompletionEngine when completing for JS
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4422
diff changeset
  1417
    JavaScriptCompletionEngine notNil ifTrue:[
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1418
        JavaScriptCompletionEngine new
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1419
           completeForMethod: methodOrNil class: classOrNil context: contextOrNil codeView: codeView into: actionBlock.
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1420
    ].
4423
c21baefab5d0 Call to JavaScriptCompletionEngine when completing for JS
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4422
diff changeset
  1421
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1422
    self information:'Not yet supported'.
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1423
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1424
    "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
  1425
    "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
  1426
! !
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1427
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1428
!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
  1429
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1430
codeCompletionForSmalltalkClass: classOrNilArg context:contextOrNilArg codeView:codeViewArg
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1431
4379
f79671ee6211 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4378
diff changeset
  1432
    "OBSOLETE; migrating to use the the new 'xxx: into:' protocol.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1433
     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
  1434
     nil, if called from the browser.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1435
     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
  1436
     This is not yet done, sigh"
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1437
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1438
    |crsrPos char interval source node parent checkedNode instanceOrNilArg
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1439
     forceNewMessageSend classOfReceiver prevChar|
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1440
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1441
    languageOrNil := SmalltalkLanguage instance.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1442
    classOrNil := classOrNilArg.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1443
    codeView := codeViewArg.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1444
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1445
    crsrPos := codeView characterPositionOfCursor"-1".
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1446
    char := codeView characterAtCharacterPosition:crsrPos.
4301
90f7571df306 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
  1447
    "/ Transcript show:crsrPos; show:' '; showCR:char.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1448
    [crsrPos > 1 and:[char isSeparator or:['.' includes:char]]] whileTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1449
        crsrPos := crsrPos - 1.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1450
        char := codeView characterAtCharacterPosition:crsrPos.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1451
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1452
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1453
    interval := codeView selectedInterval.
4301
90f7571df306 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
  1454
    "/ Transcript show:'iv: '; showCR:interval.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1455
    interval isEmpty ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1456
        interval := crsrPos"-1" to:crsrPos.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1457
        "/ Transcript show:'iv2: '; showCR:interval.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1458
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1459
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1460
    source := codeView contentsAsString string.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1461
    source := source copyTo:crsrPos.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1462
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1463
    "/ this is too naive and stupid; if there is a syntactic error,
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1464
    "/ 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
  1465
    "/ 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
  1466
    "/ without any progress.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1467
    "/ 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
  1468
    "/ as it parses the code. Stop, when the interval is hit.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1469
    "/ that will also work for syntactic incorrect source code.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1470
    classOrNil notNil ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1471
        node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:true.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1472
        "/ Transcript show:'nd1: '; showCR:node.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1473
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1474
    node isNil ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1475
        node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:false.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1476
        "/ Transcript show:'nd2 try: '; showCR:node.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1477
        node isNil ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1478
            "/ Transcript showCR:'No parseNode found (syntax error before or in comment?)'.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1479
            self breakPoint:#cg.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1480
            "/ self information:'No parseNode found (syntax error before or in comment?)'.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1481
            ^ self.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1482
        ]
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1483
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1484
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1485
    forceNewMessageSend := false.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1486
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1487
    "/ 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
  1488
    prevChar := codeView characterBeforeCursor.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1489
    (prevChar isSeparator or:[ ')}]''' includes:prevChar ]) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1490
        (node isVariable
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1491
            and:[ (parent := node parent) notNil
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1492
            and:[ parent isMessage ]]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1493
        ) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1494
            "/ completion after a variable node...
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1495
            parent isKeyword ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1496
                "/ and it is a keyword message, we complete the keyword message instead
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1497
                node := parent.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1498
            ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1499
                "/ 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
  1500
                "/ (however, no character is available to determine what is useful)
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1501
                forceNewMessageSend := true.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1502
            ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1503
        ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1504
            (node isMessage and:[node isUnary]) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1505
                "/ expanding <rcvr> foo |<- cursor here (i.e. a space after foo)
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1506
                "/
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1507
                forceNewMessageSend := true.
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1508
"/                "/ can we see what we get from foo?
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1509
"/                classOfReceiver := self
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1510
"/                                    classOfReceiver:node receiver
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1511
"/                                    inClass:classOrNil instance:instanceOrNil context:contextOrNil.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1512
"/                classOfReceiver notNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1513
"/                    |mthd|
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1514
"/
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1515
"/                    mthd := classOfReceiver lookupMethodFor:node selector.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1516
"/                    mthd notNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1517
"/                        self halt.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1518
"/                        (ParseTreeSearcher isDefinitelyGetterMethod:mthd) ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1519
"/                            forceNewMessageSend := true.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1520
"/                        ]
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1521
"/                    ]
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1522
"/                ].
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1523
            ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1524
        ]
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1525
    ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1526
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1527
    forceNewMessageSend ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1528
        "/ completion with nothing to start (right after a variable)
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1529
        "/ 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
  1530
        classOfReceiver := self classOfNode:node.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1531
        classOfReceiver isNil ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1532
            "/ 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
  1533
            "/ will be...
5687
c5be8b9eff20 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5660
diff changeset
  1534
            Screen current beepInEditor.
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1535
        ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1536
            |superClass possible choice|
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1537
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1538
            possible := classOfReceiver selectors.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1539
            superClass := classOfReceiver superclass.
4938
bedac0cfaf04 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4936
diff changeset
  1540
            [superClass notNil "and:[(possible size + superClass selectors size) < 500]"] whileTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1541
                possible := possible,superClass selectors.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1542
                superClass := superClass superclass.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1543
            ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1544
            possible := possible copy sort.
4938
bedac0cfaf04 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4936
diff changeset
  1545
            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
  1546
            choice isNil ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1547
                Screen current beep.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1548
                ^ self
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1549
            ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1550
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1551
            codeView
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1552
                undoableDo:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1553
                    codeView insertStringAtCursor:choice
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1554
                ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1555
                info:'Completion'.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1556
        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1557
        ^ self
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1558
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1559
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1560
    node isVariable ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1561
        self codeCompletionForVariable:node inClass:classOrNil codeView:codeView.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1562
        ^ self.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1563
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1564
    node isLiteral ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1565
        node value isSymbol ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1566
            self codeCompletionForLiteralSymbol:node inClass:classOrNil codeView:codeView.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1567
            ^ self.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1568
        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1569
        ^ self "/ huh - strings or what?
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1570
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1571
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1572
    checkedNode := node.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1573
    [checkedNode notNil] whileTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1574
        checkedNode isMessage ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1575
            "/ completion in a message-send
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1576
            contextOrNilArg notNil ifTrue:[
4329
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1577
"/                |rcvrNode idx rcvr val|
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1578
"/
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1579
"/                (rcvrNode := checkedNode receiver) isVariable ifTrue:[
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1580
"/                    rcvrNode isSelf ifTrue:[
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1581
"/                        classOrNil := contextOrNil receiver class.
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1582
"/                    ] ifFalse:[
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1583
"/                        (idx := contextOrNil argAndVarNames indexOf:rcvrNode name) ~~ 0 ifTrue:[
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1584
"/                            val := contextOrNil argsAndVars at:idx.
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1585
"/                            classOrNil := val class.
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1586
"/                        ] ifFalse:[
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1587
"/                            (idx := contextOrNil receiver class allInstVarNames indexOf:rcvrNode name) ~~ 0 ifTrue:[
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1588
"/                                val := contextOrNil receiver instVarNamed:rcvrNode name.
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1589
"/                                classOrNil := val class.
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1590
"/                            ]
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1591
"/                        ]
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1592
"/                    ]
2150d2f0b794 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4328
diff changeset
  1593
"/                ].
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1594
                instanceOrNilArg := contextOrNilArg receiver
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1595
            ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1596
            self
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1597
                codeCompletionForMessage:checkedNode
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1598
                inClass:classOrNil instance:instanceOrNilArg
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1599
                context:contextOrNilArg codeView:codeView.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1600
            ^ self
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1601
        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1602
        checkedNode isMethod ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1603
            "/ completion in a method's selector pattern
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1604
            self codeCompletionForMethodSpec:checkedNode.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1605
            ^ self.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1606
        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  1607
        checkedNode := checkedNode parent.
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
    self information:'Node is neither variable nor message.'.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1611
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1612
    "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
  1613
!
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1614
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1615
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
  1616
    "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
  1617
     (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
  1618
     the info as argument. 
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1619
     The interface has been defined in that way 
5509
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1620
     (and tight coupling with internals of the editor) 
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1621
     because
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1622
        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
  1623
        2) the edit operation for completion may be non-trivial
5509
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1624
           (although not yet fully implemented, non-local rewrite procedures may and will be added in the future)
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1625
           
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1626
     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
  1627
     or adding another keyword part after the cursor is possible.
4926
Claus Gittinger <cg@exept.de>
parents: 4823
diff changeset
  1628
     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
  1629
     to perform the completion.
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1630
     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
  1631
     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
  1632
     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
  1633
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1634
     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
  1635
     or nil, if called from the browser.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1636
     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
  1637
4524
54079876ac80 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4488
diff changeset
  1638
    |crsrPos char interval i source partialSource cursorLineSource
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1639
     suggestions actions title suggestionCollector|
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1640
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  1641
    languageOrNil := SmalltalkLanguage instance.
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1642
    methodOrNil := methodOrNilArg.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1643
    classOrNil := classOrNilArg.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1644
    codeView := codeViewArg.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1645
    contextOrNil := contextOrNilArg.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1646
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1647
"/    classOrNil isNil ifTrue:[
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1648
"/        self information:'No class'.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1649
"/        ^ self.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1650
"/    ].
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1651
4524
54079876ac80 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4488
diff changeset
  1652
    crsrPos := codeView characterPositionOfCursor.
4592
ba8cb2c6ef61 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4591
diff changeset
  1653
    char := codeView characterAtCharacterPosition:(crsrPos-1 max:1).
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1654
    [crsrPos > 1 and:[char isSeparator "or:['.' includes:char]"]] whileTrue:[
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1655
        crsrPos := crsrPos - 1.
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1656
        char := codeView characterAtCharacterPosition:crsrPos.
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1657
    ].
4711
1c2e635489e5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4710
diff changeset
  1658
    char == $. ifTrue:[
4591
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1659
        "/ either at end of statement or after a character constant
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1660
        crsrPos == 1 ifTrue:[^ self].
5e2aa5f1ce21 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4559
diff changeset
  1661
        (codeView characterAtCharacterPosition:crsrPos-1) == $$ ifFalse:[^ self].
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1662
    ].
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1663
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1664
    suggestionCollector :=
5509
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1665
        [:listOfSuggestions :listOfActionsOrBlock :titleWhenAsking|
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1666
            
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1667
            "/ may be called multiple times!!
5509
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1668
            "/ may also be called for duplicate suggestions!!
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1669
            suggestions isNil ifTrue:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1670
                suggestions := listOfSuggestions.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1671
                actions := listOfActionsOrBlock.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1672
            ] ifFalse:[    
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1673
                suggestions := suggestions asOrderedCollection.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1674
                actions isBlock ifTrue:[
5523
cf21c956598b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5514
diff changeset
  1675
                    actions := Array new:(suggestions size) withAll:actions.
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1676
                ].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1677
                actions := actions asOrderedCollection.
5509
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1678
                listOfSuggestions doWithIndex:[:suggestion :idx |
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1679
                    (suggestions includes:suggestion) ifFalse:[
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1680
                        suggestions add:suggestion.
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1681
                        listOfActionsOrBlock isBlock ifTrue:[
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1682
                            actions add:listOfActionsOrBlock.
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1683
                        ] ifFalse:[
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1684
                            actions add:(listOfActionsOrBlock at:idx).
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1685
                        ]
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1686
                    ]
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1687
                ].    
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1688
            ].
5509
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1689
            title := titleWhenAsking.
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1690
        ].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1691
        
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1692
    interval := crsrPos-1 to:crsrPos.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1693
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1694
    source := codeView contentsAsString string.
5931
80a7c9e6b672 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5911
diff changeset
  1695
    partialSource := source copyToMax:crsrPos.
5509
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1696
    partialSource isWhitespace ifTrue:[^ self].
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1697
    
4524
54079876ac80 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4488
diff changeset
  1698
    methodOrNilArg isNil ifTrue:[
4926
Claus Gittinger <cg@exept.de>
parents: 4823
diff changeset
  1699
        (partialSource endsWith:Character cr) ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4823
diff changeset
  1700
            partialSource := partialSource copyButLast.
Claus Gittinger <cg@exept.de>
parents: 4823
diff changeset
  1701
        ].    
5504
dbae466ee892 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5502
diff changeset
  1702
        cursorLineSource := partialSource copy.
dbae466ee892 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5502
diff changeset
  1703
5509
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1704
        "/ this cares for doIt expressions in the last cursor line;
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1705
        "/ however, we skip this, if the source starts with a lowercase letter
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1706
        "/ (then it is likely, that the user wants to define a new method)
5552
2fe0fa28ecf5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5551
diff changeset
  1707
        (partialSource isLowercaseFirst) ifFalse:[
5509
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1708
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1709
            "/ first try parsing the current cursor line.
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1710
            "/ this helps doIts in a workspace, where additional garbage is often before the actual expression to be evaluated
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1711
            (i := partialSource lastIndexOf:Character cr) ~~ 0 ifTrue:[
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1712
                "/ because cursorPositions and node-positions are required elsewhere to be correct,
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1713
                "/ I cannot just snip off the line and parse that one alone (later corrections will do so at wrong position).
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1714
                "/ Instead, create a copy of the whole source, with the stuff before the cursor line being blanked out.
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1715
                "/ However, because somewhere else, we fetch characters from the codeView using the index,
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1716
                "/ we must preserve the line structure (i.e. keep crs).
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1717
                1 to:i do:[:pos | 
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1718
                    (cursorLineSource at:pos) ~= Character cr ifTrue:[
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1719
                        cursorLineSource at:pos put:Character space.
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1720
                    ]
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1721
                ].
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1722
            ].    
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1723
            self
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1724
                tryCodeCompletionWithSource:cursorLineSource nodeInterval:interval
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1725
                at:crsrPos mustBeExpression:true
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1726
                into:suggestionCollector.
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1727
        ].
4524
54079876ac80 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4488
diff changeset
  1728
    ].
4933
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1729
    
5528
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  1730
    true "suggestions isNil" ifTrue:[
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  1731
        "/ try parsing the partial source (from beginning up to the cursor)
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  1732
        self
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  1733
            tryCodeCompletionWithSource:partialSource nodeInterval:interval
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  1734
            at:crsrPos mustBeExpression:(classOrNilArg isNil and:[methodOrNilArg isNil])
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  1735
            into:suggestionCollector.
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  1736
    ].
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  1737
5509
16997be94f7f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5508
diff changeset
  1738
    true "suggestions isEmptyOrNil" ifTrue:[
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  1739
        "/ try parsing the whole source
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  1740
        self
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  1741
            tryCodeCompletionWithSource:source nodeInterval:interval
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  1742
            at:crsrPos mustBeExpression:false
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  1743
            into:suggestionCollector
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  1744
    ].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  1745
    
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  1746
    suggestions isEmptyOrNil ifTrue:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  1747
        "/ nothing found
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  1748
        ^ self
4933
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1749
    ].    
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1750
    actionBlock value:suggestions value:actions value:title.
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1751
4392
9570ef5f05c3 Added language discrimination to code completion entry-entry proint method.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4391
diff changeset
  1752
    "Created: / 18-09-2013 / 15:25:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
5552
2fe0fa28ecf5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5551
diff changeset
  1753
    "Modified: / 22-06-2017 / 06:56:30 / cg"
5931
80a7c9e6b672 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5911
diff changeset
  1754
    "Modified: / 02-11-2018 / 20:17:48 / Claus Gittinger"
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1755
! !
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1756
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1757
!DoWhatIMeanSupport methodsFor:'code completion - obsolete'!
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1758
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1759
codeCompletionForClass:classOrNilArg context:contextOrNil codeView:codeViewArg
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1760
    <resource: #obsolete>
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1761
    "OBSOLETE; migrating to use the the new 'xxx: into:' protocol.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1762
     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
  1763
     nil, if called from the browser.
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1764
     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
  1765
     This is not yet done, sigh"
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1766
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1767
    ^self codeCompletionForLanguage: nil class:classOrNilArg context:contextOrNil codeView:codeViewArg
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1768
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1769
    "Modified: / 04-07-2006 / 18:48:26 / fm"
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1770
    "Modified: / 28-08-2013 / 17:15:25 / cg"
4391
903ec83fb9cd class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4390
diff changeset
  1771
    "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
  1772
!
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1773
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1774
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
  1775
    <resource: #obsolete>
4524
54079876ac80 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4488
diff changeset
  1776
    ^ self
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1777
	codeCompletionForSmalltalkMethod:methodOrNilArg orClass:classOrNilArg context:contextOrNilArg codeView:codeViewArg into:actionBlock
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1778
! !
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1779
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1780
!DoWhatIMeanSupport methodsFor:'code completion-helpers'!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1781
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1782
askUserForCompletion:what for:codeView at:position from:allTheBest
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1783
    |list choice lastChoice|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1784
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1785
    "/ cg: until the new stuff works,...
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1786
    ^ self old_askUserForCompletion:what for:codeView from:allTheBest.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1787
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1788
"/    allTheBest isEmpty ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1789
"/        ^ nil
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1790
"/    ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1791
"/    allTheBest size == 1 ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1792
"/        ^ allTheBest first
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1793
"/    ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1794
"/    list := allTheBest.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1795
"/    LastChoices notNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1796
"/        lastChoice := LastChoices at:what ifAbsent:nil.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1797
"/        lastChoice notNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1798
"/            list := { lastChoice allBold } , (list copyWithout:lastChoice).
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1799
"/        ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1800
"/    ].
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  1801
"/    choice := Tools::CodeCompletionMenu
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1802
"/                openFor:codeView
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1803
"/                at:position
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1804
"/                with:allTheBest.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1805
"/    LastChoices isNil ifTrue:[
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1806
"/        LastChoices := Dictionary new.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1807
"/    ].
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1808
"/    LastChoices at:what put:choice.
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  1809
"/    ^ choice string
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1810
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1811
    "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
  1812
    "Modified: / 28-08-2013 / 16:41:35 / cg"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1813
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1814
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1815
askUserForCompletion:what for:codeView from:allTheBest
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1816
    |list resources choice lastChoice|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1817
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1818
    allTheBest isEmpty ifTrue:[ ^ nil ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1819
    allTheBest size == 1 ifTrue:[ ^ allTheBest first ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1820
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1821
    list := allTheBest.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1822
    LastChoices notNil ifTrue:[
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1823
	lastChoice := LastChoices at:what ifAbsent:nil.
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1824
	lastChoice notNil ifTrue:[
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1825
	    list := {lastChoice. nil. } , (list copyWithout:lastChoice).
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1826
	].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1827
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1828
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1829
    list size < 30 ifTrue:[
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1830
	|menu idx exitKey|
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1831
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1832
	menu := PopUpMenu labels:list.
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1833
	menu hideOnKeyFilter:[:key | |hide|
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1834
		hide := ( #( CursorDown CursorUp Escape Return ) includes: key) not.
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1835
		hide ifTrue:[
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1836
		    exitKey := key.
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1837
		].
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1838
		hide].
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1839
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1840
	idx := menu startUp.
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1841
	idx == 0 ifTrue:[
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1842
	    exitKey notNil ifTrue:[
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1843
		codeView keyPress:exitKey x:0 y:0.
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1844
	    ].
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1845
	    ^ nil
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1846
	].
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1847
	choice := list at:idx.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1848
    ] ifFalse:[
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1849
	resources := codeView application isNil
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1850
			ifTrue:[ codeView resources]
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1851
			ifFalse:[ codeView application resources ].
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1852
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1853
	choice := Dialog
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1854
	   choose:(resources string:'Choose ',what)
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1855
	   fromList:list
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1856
	   lines:20
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1857
	   title:(resources string:'Code completion').
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1858
	choice isNil ifTrue:[^ nil].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1859
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1860
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1861
    LastChoices isNil ifTrue:[
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1862
	LastChoices := Dictionary new.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1863
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1864
    LastChoices at:what put:choice.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1865
    ^ choice
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1866
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1867
    "Created: / 10-11-2006 / 14:00:53 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1868
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1869
5106
5303d78eb69a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5104
diff changeset
  1870
codeCompletionForBlockArgument:node into:actionBlock
5303d78eb69a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5104
diff changeset
  1871
!
5303d78eb69a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5104
diff changeset
  1872
5900
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  1873
codeCompletionForLiteralString:partialString node:node considerAll:considerAll into:actionBlock
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  1874
    "/ nothing done here, but redefined in subclasses which may (i.e. expecco code completer)
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  1875
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  1876
    "Created: / 29-08-2018 / 16:31:22 / Claus Gittinger"
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  1877
!
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  1878
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  1879
codeCompletionForLiteralString:partialString node:node in:source considerAll:considerAll into:actionBlock
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  1880
    "/ nothing done here, but redefined in subclasses which may (i.e. expecco code completer)
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  1881
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  1882
    "Created: / 29-08-2018 / 16:47:28 / Claus Gittinger"
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  1883
!
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  1884
4382
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1885
codeCompletionForLiteralSymbol:nodeOrNil element:tokenOrNil considerAll:considerAll into:actionBlock
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1886
    "looking for all symbols is way too much and imprecise;
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1887
     experiment: only present symbols which are used by the class,
4544
a07061d382ce class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4543
diff changeset
  1888
     and classes in that class category, or at least: implemented as method.
a07061d382ce class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4543
diff changeset
  1889
     We'll see..."
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1890
4382
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1891
    |sym possibleCompletions longest editAction start stop addSymbol
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1892
     parentSelector parent symbolSelectorClass|
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1893
4302
f115f2ff999d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
  1894
    "/ Transcript show:'lit in '; show:methodOrNil; show:' / '; showCR:classOrNil.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1895
4382
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1896
    start := (nodeOrNil ? tokenOrNil) start.
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1897
    stop := (nodeOrNil ? tokenOrNil) stop.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1898
    (codeView characterAtCharacterPosition:stop) == $' ifTrue:[
5031
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1899
        ^ self.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1900
    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1901
4382
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1902
    sym := (nodeOrNil ? tokenOrNil) value.
4544
a07061d382ce class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4543
diff changeset
  1903
    possibleCompletions := Set new.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1904
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1905
    addSymbol :=
5031
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1906
        [:aSymbol |
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1907
            (aSymbol startsWith:sym) ifTrue:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1908
                (aSymbol = sym) ifFalse:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1909
                    possibleCompletions add:aSymbol
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1910
                ].
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1911
            ].
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1912
        ].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1913
4382
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1914
    (nodeOrNil notNil
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1915
    and:[ (parent := nodeOrNil parent) notNil
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1916
    and:[ parent isMessage ]]) ifTrue:[
5031
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1917
        parentSelector := parent selector.
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1918
        ( #( perform: perform:ifNotUnderstood: ) includes: parentSelector) ifTrue:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1919
            symbolSelectorClass := self classOfNode:parent receiver.
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1920
        ].
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1921
        ( #( #'onChangeSend:' ) includes: parentSelector) ifTrue:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1922
            "/ assume that send-target will be self.
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1923
            (methodOrNil notNil and:[ methodOrNil selector notNil and:[ methodOrNil selector isUnarySelector ]]) ifTrue:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1924
                addSymbol value:(methodOrNil selector,'Changed').
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1925
            ].
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1926
            symbolSelectorClass := classOrNil.
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1927
        ].
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1928
        ( #( #'onChangeSend:to:' ) includes: parentSelector) ifTrue:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1929
            symbolSelectorClass := self classOfNode:parent arguments second.
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1930
        ].
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1931
5074
1f0c4ef255d8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5071
diff changeset
  1932
        "/ actually, I found that this gives good suggestions.
1f0c4ef255d8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5071
diff changeset
  1933
        symbolSelectorClass isNil ifTrue:[
1f0c4ef255d8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5071
diff changeset
  1934
            symbolSelectorClass := classOrNil.
1f0c4ef255d8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5071
diff changeset
  1935
        ].
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1936
5031
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1937
        symbolSelectorClass notNil ifTrue:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1938
            symbolSelectorClass withAllSuperclassesDo:[:cls |
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1939
                cls ~~ Object ifTrue:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1940
                    cls ~~ Model ifTrue:[
5462
6a7b577cd2b9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5453
diff changeset
  1941
                        cls selectorsDo:addSymbol.
5031
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1942
                    ]
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1943
                ]
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1944
            ]
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1945
        ].
4382
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1946
    ].
e92f704c63ec class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4381
diff changeset
  1947
4368
442517f0d19d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
  1948
    (considerAll or:[classOrNil isNil]) ifTrue:[
5031
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1949
        Smalltalk allClassesDo:[:cls |
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1950
            cls theNonMetaclass methodDictionary keys do:addSymbol.
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1951
            cls theMetaclass methodDictionary keys do:addSymbol.
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1952
        ].
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1953
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1954
        "/ Symbol allInstancesDo:addSymbol.
4368
442517f0d19d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
  1955
    ] ifFalse:[
5031
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1956
        Smalltalk allClassesInCategory:classOrNil do:[:cls |
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1957
            cls theNonMetaclass instAndClassMethodsDo:[:mthd |
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1958
                mthd usedSymbols do:addSymbol
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1959
            ]
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1960
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  1961
    ].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1962
5031
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1963
    "/ add symbolic literals (especially for spec methods)
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1964
    classOrNil notNil ifTrue:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1965
        classOrNil theMetaclass instAndClassMethodsDo:[:mthd |
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1966
            mthd literalsDo:[:lit |
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1967
                lit isSymbol ifTrue:[ addSymbol value: lit ]
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1968
            ].
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1969
        ].
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1970
    ].
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  1971
4544
a07061d382ce class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4543
diff changeset
  1972
    possibleCompletions := possibleCompletions asOrderedCollection sort.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1973
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1974
    longest := possibleCompletions longestCommonPrefix.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1975
    possibleCompletions remove:longest ifAbsent:[].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1976
    possibleCompletions addFirst: longest.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1977
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  1978
    editAction :=
5031
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1979
        [:chosenIndex |
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1980
            |chosen oldSym oldLen newLen|
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1981
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1982
            chosen := possibleCompletions at:chosenIndex.
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1983
            chosen notNil ifTrue:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1984
                (codeView characterAtCharacterPosition:start) == $# ifTrue:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1985
                    start := start + 1.
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1986
                ].
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1987
                (codeView characterAtCharacterPosition:start) == $' ifTrue:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1988
                    start := start + 1.
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1989
                ].
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1990
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1991
                oldSym := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators.
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1992
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1993
                codeView
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1994
                    undoableDo:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1995
                        codeView replaceFromCharacterPosition:start to:stop with:chosen
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1996
                    ]
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1997
                    info:'Completion'.
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1998
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  1999
                (chosen startsWith:oldSym) ifTrue:[
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  2000
                    oldLen := stop - start + 1.
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  2001
                    newLen := chosen size.
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  2002
                    codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  2003
                    codeView dontReplaceSelectionOnInput
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  2004
                ].
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  2005
            ]
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  2006
        ].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2007
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2008
    actionBlock value:possibleCompletions value:editAction value:'symbol'.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2009
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2010
    "Modified: / 16-02-2010 / 10:15:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
5462
6a7b577cd2b9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5453
diff changeset
  2011
    "Modified: / 10-02-2017 / 10:32:54 / cg"
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  2012
    "Modified (comment): / 17-05-2017 / 12:13:33 / mawalch"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2013
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2014
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2015
codeCompletionForMessage:node into:actionBlock
5031
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  2016
    "find good completions for a message selector in a message-send node"
ea94aa3cb834 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5027
diff changeset
  2017
    
5613
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  2018
    |selector lcSelector selectorWithoutColon lcSelectorWithoutColon
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  2019
     bestSelectors parentSelector newParentSelector bestSelectors2 bestWithParenthesis allBest numArgs
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2020
     newParts nSelParts oldLen newLen selectorParts
5112
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  2021
     parentNode nodeReceiver "selectorsSentInCode" selectorsImplementedInClass
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2022
     editAction parentNodeClassIfKnown
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2023
     receiverNodeClassIfKnown 
5071
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2024
     offerParenthisationAroundNode parenthesisAroundIndex parentNodeToParenthesize
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2025
     offerValueInsertion valueToInsert valueToInsertIndex valueInfo
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2026
     classesFromAssignmentsToReceiver otherMessagesToReceiver
5103
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2027
     canParenthesize classesOfReceiver|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2028
 
5112
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  2029
    Verbose == true ifTrue:[
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  2030
        Transcript show:'node '; show:node; show:' ; '.
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  2031
        Transcript show:'msg in '; show:methodOrNil; show:' / '; showCR:classOrNil.
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  2032
    ].
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  2033
    
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2034
    offerParenthisationAroundNode := nil.
5071
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2035
    offerValueInsertion := false.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2036
 
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2037
    selector := node selector.
4936
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2038
    lcSelector := selector asLowercase.
5613
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  2039
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  2040
    selectorWithoutColon := selector.
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  2041
    lcSelectorWithoutColon := lcSelector.
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  2042
    (selectorWithoutColon includes:$:) ifTrue:[
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  2043
        selectorWithoutColon := selector upTo:$:.
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  2044
    ].    
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  2045
    (lcSelectorWithoutColon includes:$:) ifTrue:[
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  2046
        lcSelectorWithoutColon := lcSelector upTo:$:.
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  2047
    ].    
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  2048
        
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2049
    parentNode := node parent.
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2050
    nodeReceiver := node receiver.
5103
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2051
    nodeReceiver notNil ifTrue:[
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2052
        classesOfReceiver := self classesOfNode:nodeReceiver.
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2053
    ].
6036
171e12f06b70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6022
diff changeset
  2054
    "/ Verbose := true
5112
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  2055
    Verbose == true ifTrue:[
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  2056
        Transcript show:node; show:' -> '; showCR:classesOfReceiver.
5738
59d8e9757a0f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5714
diff changeset
  2057
        ( node isVariable and:[node name = 'self']) ifTrue:[self breakPoint:#cg].
5112
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  2058
    ].
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  2059
    
4366
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  2060
    "/ 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
  2061
    "/ do not attempt to complete the current message.
4366
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  2062
    "/ If it is a message, we will look for parent-message completion also below (best2 stuff)
5385
730032499904 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 5379
diff changeset
  2063
    (codeView characterBeforeCursor ? Character space) isSeparator ifTrue:[
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2064
        selector isKeyword ifFalse:[
5041
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  2065
            self codeCompletionForMessageTo:node into:actionBlock.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2066
            ^ self
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2067
        ].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2068
    ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2069
 
4620
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  2070
    "/ only do this if the node-message has no parents around
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  2071
    node parentheses isEmptyOrNil ifTrue:[
5112
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  2072
        Verbose == true ifTrue:[
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  2073
            Transcript show:'try for: '; showCR:nodeReceiver
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  2074
        ].    
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  2075
        bestSelectors := self findBest:nodeReceiver for:selector 
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  2076
                              inClasses:classesOfReceiver
4620
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  2077
    ] ifFalse:[
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  2078
        bestSelectors := OrderedCollection new.
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  2079
    ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2080
 
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2081
    "/ if the receiver is a real variable,
4386
d5b6d7c0b6ee class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4385
diff changeset
  2082
    "/ we can look for other messages being sent to that variable in the current method.
5042
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2083
    "/ Also, if there are assignments to it (like constants or '<class> new'), use that as a hint...
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2084
    (tree notNil
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2085
        and:[ nodeReceiver isVariable
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2086
        and:[ nodeReceiver isSelf not
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2087
        and:[ nodeReceiver isSuper not ]]])
4366
8041b628bba3 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  2088
    ifTrue:[
5042
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2089
        |receiverName possibleClasses possibleClassesFromOtherSends|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2090
 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2091
        receiverName := nodeReceiver name.
5486
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2092
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2093
        classesOfReceiver notEmptyOrNil ifTrue:[ 
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2094
            possibleClasses := classesOfReceiver.
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2095
        ] ifFalse:[    
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2096
            classesFromAssignmentsToReceiver := self classesFromAssignmentTo:receiverName in:tree.
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2097
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2098
            possibleClasses := classesFromAssignmentsToReceiver.
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2099
            possibleClasses isEmpty ifTrue:[
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2100
                "/ messages sent
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2101
                otherMessagesToReceiver := self messagesSentTo:receiverName in:tree.
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2102
                otherMessagesToReceiver remove:selector ifAbsent:[].
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2103
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2104
                otherMessagesToReceiver notEmpty ifTrue:[
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2105
                    "/ classes which respond to all
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2106
                    possibleClassesFromOtherSends :=
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2107
                        Smalltalk 
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2108
                            allClassesForWhich:[:cls |
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2109
                                cls isLoaded
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2110
                                and:[ otherMessagesToReceiver
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2111
                                        conform:[:eachSelectorSent | cls canUnderstand:eachSelectorSent]]
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2112
                            ].
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2113
                    possibleClasses := possibleClasses , possibleClassesFromOtherSends.
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2114
                ].
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2115
            ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2116
 
5486
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2117
            "/ if the receiver is a classVar/classInstVar,
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2118
            "/ include the class of its current value and UndefinedObject.
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2119
            "/ This helps to complete class methods and (lazy) initializer code.
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2120
            (classOrNil notNil) ifTrue:[
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2121
                |tryValue currentValue|
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2122
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2123
                tryValue := false.
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2124
                (classOrNil theNonMetaclass allClassVarNames includes: receiverName) ifTrue:[
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2125
                    tryValue := true.
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2126
                    currentValue := classOrNil theNonMetaclass classVarAt:receiverName.
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2127
                ] ifFalse:[
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2128
                    (classOrNil isMeta and:[ classOrNil allInstVarNames includes: receiverName ]) ifTrue:[
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2129
                        tryValue := true.
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2130
                        currentValue := classOrNil theNonMetaclass instVarNamed:receiverName.
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2131
                    ].
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2132
                ].
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2133
                tryValue ifTrue:[
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2134
                    possibleClasses := { currentValue class } , possibleClasses.
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2135
                ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2136
            ].
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2137
        ].
5486
56dd440a7ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5471
diff changeset
  2138
        
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2139
        (possibleClasses notEmpty and:[possibleClasses size < 15]) ifTrue:[
4933
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2140
            bestSelectors :=
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2141
                (possibleClasses 
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2142
                    collectAll:[:eachClass |
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2143
                        Parser findBest:30 selectorsFor:selector in:eachClass forCompletion:true.
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  2144
                    ] as:Set) asOrderedCollection.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2145
 
4619
edb90d73576b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4618
diff changeset
  2146
            "/ if any of those is a prefix-keyword of the selector,
edb90d73576b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4618
diff changeset
  2147
            "/ do not offer it (i.e. ifTrue:ifFalse: is already present, don't offer ifTrue:ifFalse: again.
5613
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  2148
            bestSelectors := bestSelectors reject: [:sel | 
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  2149
                                (selector startsWith: sel) or: [selector endsWith: sel]
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  2150
                             ].
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2151
        ].
4619
edb90d73576b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4618
diff changeset
  2152
    ].                                                                            
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2153
 
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2154
    "/ if we are behind a keyword messages colon,
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2155
    "/ only look for matching prefix selectors;
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2156
    "/ also, a good completion is to insert an argument;
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2157
    "/ the name of the variable from the implementation, as comment, and selected might be a good one!!
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2158
    "/ Array new:1
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2159
    selector isKeyword ifTrue:[
5385
730032499904 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 5379
diff changeset
  2160
        (node arguments size = selector argumentCount) ifTrue:[
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2161
            offerParenthisationAroundNode := node. 
5042
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2162
            "/ Transcript show:'2:'; showCR:node.
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2163
        ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2164
 
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2165
        codeView characterBeforeCursor == $: ifTrue:[
5613
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  2166
            (bestSelectors select:[:sel | sel asLowercase startsWith:lcSelectorWithoutColon]) isEmpty ifTrue:[
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2167
                "/ nothing better around
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2168
                |argIndex argNames argNameStrings impls|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2169
 
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2170
                argIndex := node selectorParts size.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2171
                argNames := Set new.
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2172
                argNameStrings := OrderedCollection new.
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2173
                impls := Smalltalk allImplementorsOf:selector.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2174
                impls size < 10 ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2175
                    impls do:[:eachImplClass |
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2176
                        |mthd argName|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2177
 
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2178
                        mthd := (eachImplClass compiledMethodAt:selector).
4764
3142fc3b57cd class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4731
diff changeset
  2179
                        argName := (mthd methodArgNames ? #()) at:argIndex ifAbsent:nil.
3142fc3b57cd class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4731
diff changeset
  2180
                        argName notNil ifTrue:[
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2181
                            (argNames includes:argName) ifFalse:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2182
                                argNames add:argName.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2183
                                argNameStrings add:(argName allItalic,' hint only: argName in (' ,mthd mclass name allBold,' ',mthd methodDefinitionTemplate).
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2184
                            ].    
4764
3142fc3b57cd class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4731
diff changeset
  2185
                        ].
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2186
                    ].
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2187
                    argNameStrings notEmptyOrNil ifTrue: [
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2188
                        argNameStrings := argNameStrings asOrderedCollection sort.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2189
                        actionBlock value:argNameStrings value:[:selIndex | ] value: 'argument name hint'.
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2190
                        ^ self.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2191
                    ]
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2192
                ]
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2193
            ].
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2194
        ].
4369
810a78e62f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2195
    ] ifFalse:[
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2196
        "/ when completing a non-keyword AND the parent is a keyword message,
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2197
        "/ only consider longer keyword messages or unary messages.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2198
        "/ unless the node is parenthesized
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2199
        node hasParentheses ifFalse:[ 
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2200
            (parentNode notNil and:[ parentNode isKeywordMessage ]) ifTrue:[
5613
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  2201
                bestSelectors := bestSelectors select:[:sel |
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  2202
                                    sel isUnarySelector 
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  2203
                                    or:[ sel startsWith:parentNode selector]
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  2204
                                 ]
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2205
            ]
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2206
        ]
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2207
    ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2208
 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2209
"/    bestSelectors := bestSelectors asOrderedCollection.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2210
"/    bestSelectors sort:[:a :b | a size < b size].
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2211
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2212
    (selector isUnarySelector and:[ parentNode notNil and:[ parentNode isMessage ]]) ifTrue:[
5058
925bc542ebd1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5052
diff changeset
  2213
        (parentSelector := parentNode selector) isKeyword ifTrue:[
5471
289b60e70a2c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5462
diff changeset
  2214
            "/ if it's a unary message AND the parent is a keyword node, look for parent completion too.
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2215
            "/ i.e. look if there is a longer keyword possible
5058
925bc542ebd1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5052
diff changeset
  2216
            newParentSelector := parentSelector,selector.
5112
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  2217
            bestSelectors2 := self 
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  2218
                                findBest:(parentNode receiver) for:newParentSelector 
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  2219
                                inClasses:(self classesOfNode:parentNode receiver).
5058
925bc542ebd1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5052
diff changeset
  2220
            bestSelectors2 := bestSelectors2 select:[:sel | sel isKeyword and:[ sel startsWith:parentSelector]].
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2221
            bestSelectors2 := bestSelectors2 asOrderedCollection sort:[:a :b | a size < b size].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2222
            bestSelectors := bestSelectors reject:[:sel | bestSelectors2 includes:sel].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2223
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2224
            "/ if the parent has a valid selector, offer parenthization
5058
925bc542ebd1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5052
diff changeset
  2225
            (Smalltalk someImplementorOf:parentSelector) notNil ifTrue:[
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2226
                offerParenthisationAroundNode := parentNode.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2227
                "/ Transcript show:'2:'; showCR:parentNode.
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2228
            ].
5528
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  2229
            parentSelector := newParentSelector.
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2230
        ] ifFalse:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2231
            |kwSels|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2232
 
5103
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2233
            "/ if its a unary message AND the parent is a unary or binary node, 
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2234
            "/ try again, sending the partial message
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2235
            "/ as a keyword to the parent node.
5103
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2236
            "/ this is the case when after "foo binOp bar if", or "foo unOp bar if"
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2237
            "/ which should include ifTrue: in the suggestion result.
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2238
            
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2239
            "/ suggestion will transform from (the incorrectly parsed)
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2240
            "/    foo == (shift if)
5103
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2241
            "/
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2242
            "/        nonKWsel-msg(parent)
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2243
            "/     /         \
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2244
            "/    /           \
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2245
            "/  rcvr         sel-unary(node)
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2246
            "/              /
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2247
            "/             /
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2248
            "/           arg
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2249
            "/
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2250
            "/ into:
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2251
            "/    (foo == shift) if
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2252
            "/
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2253
            "/        nonKWsel-msg(parent)
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2254
            "/     /         \
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2255
            "/    /           \
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2256
            "/  rcvr         sel-unary(node)
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2257
            "/              /
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2258
            "/             /
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2259
            "/           arg
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2260
 
5103
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2261
            "/ but only do this, if typing to the end of the parent message
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2262
            "/ (i.e. after (foo == shift) <-
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2263
            "/    or after foo bar baz <-
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2264
            "/ not if typing into an existing message
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2265
            "/ (i.e. into foo == shift <- more
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2266
            "/    or into foo bar <- baz
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2267
            codeView characterPositionOfCursor >= parentNode stop ifTrue:[
5112
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  2268
                kwSels := self 
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  2269
                                findBest:parentNode for:selector 
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  2270
                                inClasses:(self classesOfNode:parentNode).
5103
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2271
                kwSels := kwSels select:[:sel | sel isKeyword].
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2272
     
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2273
                kwSels := kwSels asOrderedCollection sort:[:a :b | a size < b size].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2274
 
5103
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2275
                bestSelectors := bestSelectors reject:[:sel | kwSels includes:sel].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2276
 
5103
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2277
                "/ these need to go to bestSelectors (see editAction)
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2278
                parentNodeClassIfKnown := self classOfNode:parentNode.
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2279
                (parentNodeClassIfKnown notNil and:[ parentNodeClassIfKnown includesBehavior: Boolean ]) ifTrue:[
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2280
                    "/ this is so common, that it deserves a special case:
5453
4e5f952f555d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5451
diff changeset
  2281
                    "/ if we complete an 'if' after some boolean message e.g '(a == b) if'
5103
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2282
                    "/ throw out the very unlikely ifNil, ifEmpty etc. messages (which are inherited by Object, but absolutely unrealistic)
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2283
                    bestSelectors := self
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2284
                                        withoutSelectorsUnlikelyFor:parentNodeClassIfKnown
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2285
                                        from:bestSelectors
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2286
                                        forPartial:selector.
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2287
                    kwSels := self
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2288
                                withoutSelectorsUnlikelyFor:parentNodeClassIfKnown
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2289
                                from:kwSels
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2290
                                forPartial:selector.
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2291
     
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2292
                    "/ put keyword selectors in front, because they are very likely
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2293
                    bestSelectors := kwSels , bestSelectors.
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2294
                ] ifFalse:[
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2295
                    "/ put them at the end
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2296
                    bestSelectors := bestSelectors , kwSels.
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2297
                ].
fc854b0d6ee8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5102
diff changeset
  2298
            ]
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2299
        ]
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2300
    ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2301
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2302
    (selector isUnarySelector and:[ node isMessage ]) ifTrue:[
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2303
        receiverNodeClassIfKnown := self classOfNode:nodeReceiver.
5453
4e5f952f555d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5451
diff changeset
  2304
4e5f952f555d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5451
diff changeset
  2305
        (receiverNodeClassIfKnown notNil) ifTrue:[
4e5f952f555d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5451
diff changeset
  2306
            true "(receiverNodeClassIfKnown includesBehavior: Boolean)" ifTrue:[
4e5f952f555d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5451
diff changeset
  2307
                bestSelectors := bestSelectors select:[:sel | receiverNodeClassIfKnown canUnderstand:sel].
4e5f952f555d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5451
diff changeset
  2308
                bestSelectors := self
4e5f952f555d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5451
diff changeset
  2309
                                    withoutSelectorsUnlikelyFor:receiverNodeClassIfKnown
4e5f952f555d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5451
diff changeset
  2310
                                    from:bestSelectors
4e5f952f555d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5451
diff changeset
  2311
                                    forPartial:selector.
4e5f952f555d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5451
diff changeset
  2312
            ].
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2313
        ].
4375
305981eb7976 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4374
diff changeset
  2314
    ].
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2315
    
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2316
    Verbose == true ifTrue:[    
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2317
        Transcript show:'parentNode: '; showCR:parentNode.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2318
        Transcript show:'parentNode: '; showCR:parentNode class.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2319
        Transcript show:'sel: '; showCR:selector.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2320
    ].
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2321
    
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2322
    canParenthesize := false.
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2323
    parentNode notNil ifTrue:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2324
        parentNode isMessage ifTrue:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2325
            (((parentNode selector isUnarySelector not) and:[selector isUnarySelector])
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2326
            or:[ ((parentNode selector isKeyword) and:[selector isBinarySelector]) ]) ifTrue:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2327
                canParenthesize := true.
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2328
            ]
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2329
        ] ifFalse:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2330
            offerParenthisationAroundNode isNil ifTrue:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2331
                selector isKeyword ifTrue:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2332
                    offerParenthisationAroundNode := node.
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2333
                ].    
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2334
            ].    
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2335
        ].    
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2336
    ].    
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2337
    canParenthesize ifTrue:[
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2338
        "/ completing an already existing keyword or binary message with something starting with
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2339
        "/ if, and, or or while.
5203
9b8272cc6d49 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5146
diff changeset
  2340
        "/ Here, offer a special completion which inserts parentheses / brackets around the already
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2341
        "/ existing message. Do this only, if the existing message makes sense.
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2342
        "/    expr wh
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2343
        "/ ->
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2344
        "/    [expr] whileXX:[]
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2345
        true "((
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2346
            #( 'ifTrue' 'ifFalse' 'and' 'or' 'do' 'keysAndValuesDo' 'whileTrue' 'whileFalse' 'ensure' 'on')
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2347
        ) contains:[:part | part startsWith:selector])" ifTrue:[
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2348
            (Smalltalk someImplementorOf:parentNode selector) notNil ifTrue:[
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2349
                |selsP selsB|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2350
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2351
                selsP := #( 'ifTrue:' 'ifFalse:' 'and' 'or' 'do' 'keysAndValuesDo' )
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2352
                            select:[:sel | sel startsWith:selector]
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2353
                            thenCollect:[:sel | '(',parentNode selector,') ',sel].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2354
                ( #( 'whileTrue:' 'whileFalse:' 'ensure:' 'on:do:' ) contains:[:sel | sel startsWith:selector]) 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2355
                ifFalse:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2356
                    selsP := selsP copyWith:'(',parentNode selector,') ',selector  
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2357
                ]. 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2358
                selsB := #( 'whileTrue:' 'whileFalse:' 'ensure:' 'on:do:' )
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2359
                            select:[:sel | sel startsWith:selector]
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2360
                            thenCollect:[:sel | '[',parentNode selector,'] ',sel].
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2361
                parentNodeToParenthesize := parentNode.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2362
                bestWithParenthesis := selsP , selsB.
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2363
            ].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2364
        ].
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  2365
    ] ifFalse:[
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2366
        "/ also offer adding brackets for a while expression
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2367
        "/    expr wh
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2368
        "/ ->
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2369
        "/    [expr] whileXX:[]
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2370
        ((
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2371
            #( 'whileTrue' 'whileFalse' 'ensure' 'on')
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2372
        ) contains:[:part | part startsWith:selector]) ifTrue:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2373
            (node receiver isBlock) ifFalse:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2374
                |sels|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2375
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2376
                (node receiver isMessage not
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2377
                or:[ (Smalltalk someImplementorOf:node receiver selector) notNil ]) ifTrue:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2378
                    sels := #( 'whileTrue:' 'whileFalse:' 'ensure:' 'on:do:' )
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2379
                                select:[:sel | sel startsWith:selector]
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2380
                                thenCollect:[:sel | '[...] ',sel].
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2381
                    parentNodeToParenthesize := node receiver.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2382
                    bestWithParenthesis := sels.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2383
                ].
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2384
            ].
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2385
        ].
4416
ebb04dca4484 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4413
diff changeset
  2386
    ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2387
 
5419
7ba6ce8016c2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5392
diff changeset
  2388
    allBest := (bestSelectors ? #()) , (bestSelectors2 ? #()) asOrderedCollection.
5613
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  2389
    self sortSelectors:allBest forSelector:selectorWithoutColon lcSelector:lcSelectorWithoutColon.
4936
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2390
                        
4388
a2a5955d733c class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
  2391
    "/ sort: prefixes first.
5058
925bc542ebd1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5052
diff changeset
  2392
    parentSelector notNil ifTrue:[
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2393
        allBest := self 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2394
                    splitSelectorList:allBest 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2395
                    by:[:sel | 
5613
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  2396
                            (sel asLowercase startsWith:lcSelectorWithoutColon) 
5058
925bc542ebd1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5052
diff changeset
  2397
                            or:[sel startsWith:parentSelector]].
4388
a2a5955d733c class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4387
diff changeset
  2398
    ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2399
 
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  2400
    "/ if receiver is super, always include the method's own selector
4408
18567ee46c6a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4407
diff changeset
  2401
    nodeReceiver isSuper ifTrue:[
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2402
        (tree isMethod) ifTrue:[
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2403
            |mSel|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2404
 
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2405
            mSel := tree selector.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2406
            mSel notNil ifTrue:[
5613
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  2407
                (mSel startsWith:selectorWithoutColon) ifTrue:[
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2408
                    "/ already the word before the cursor?
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2409
                    (mSel ~= selector) ifTrue:[
5419
7ba6ce8016c2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5392
diff changeset
  2410
                        allBest removeAndAddFirst:mSel.
4610
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
            ]
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2414
        ]
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2415
    ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2416
 
5071
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2417
    "/ another convenient hack; 
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2418
    "/ if we have just typed in foo == 
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2419
    "/ and the value of foo is a known literal,
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2420
    "/ offer inserting this literal. This is great in a debugger...
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2421
    ( #(#'==' #'=' #'~=' #'~~') includes:selector ) ifTrue:[
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2422
        |val|
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2423
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2424
        (val := self valueOfNode:nodeReceiver) notNil ifTrue:[
5285
6472a320f8d4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
  2425
            "/ this can raise an error, if val does not like to generate a storeString
6472a320f8d4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
  2426
            "/ (it is recursive, or an X11GraphicsContext, for example)
6472a320f8d4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
  2427
            Error handle:[:ex |
6472a320f8d4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
  2428
            ] do:[
6472a320f8d4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
  2429
                valueToInsert := val storeString.
6472a320f8d4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
  2430
                offerValueInsertion := true.
6472a320f8d4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
  2431
                nodeReceiver isVariable ifTrue:[
6472a320f8d4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
  2432
                    valueInfo := ' (current value of %1)' bindWith:nodeReceiver name.
6472a320f8d4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
  2433
                ] ifFalse:[                
6472a320f8d4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
  2434
                    valueInfo := ' (current value of expression)'.
6472a320f8d4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
  2435
                ].
6472a320f8d4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5274
diff changeset
  2436
                valueInfo := valueInfo withColor:(Color grey).
5071
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2437
            ].
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2438
        ].    
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2439
    ].    
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2440
    
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2441
    (allBest isEmptyOrNil 
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2442
        and:[bestWithParenthesis isEmptyOrNil
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2443
        and:[offerParenthisationAroundNode isNil
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2444
        and:[offerValueInsertion not]]] 
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2445
    ) ifTrue:[ 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2446
        ^ self 
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2447
    ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2448
 
5042
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2449
"/    "/ see what is aready sent to this variable inside the code
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2450
"/    "/ and also what is assigned to it.
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2451
"/    nodeReceiver notNil ifTrue:[
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2452
"/        nodeReceiver isVariable ifTrue:[
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2453
"/            rememberedNodes notNil ifTrue:[
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2454
"/                selectorsSentInCode := 
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2455
"/                    (rememberedNodes
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2456
"/                        select:[:node | 
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2457
"/                            node isMessage 
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2458
"/                                and:[node receiver isVariable
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2459
"/                                and:[node receiver name = nodeReceiver name]]]
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2460
"/                        thenCollect:[:node | 
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2461
"/                            node selector]
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2462
"/                    ) asSet.
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2463
"/            ] ifFalse:[
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2464
"/                selectorsSentInCode := Set new. 
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2465
"/                tree allMessageNodesDo:[:msg |
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2466
"/                    (msg receiver isVariable
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2467
"/                        and:[msg receiver name = nodeReceiver name]
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2468
"/                    ) ifTrue:[
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2469
"/                        selectorsSentInCode add:msg selector
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2470
"/                    ].
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2471
"/                ].
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2472
"/                selectorsSentInCode remove:selector ifAbsent:[].
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2473
"/            ]. 
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2474
"/        ]. 
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2475
"/    ]. 
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2476
4936
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2477
    nodeReceiver notNil ifTrue:[
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2478
        |classOrNil|
5042
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2479
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2480
        classOrNil := self classOfNode:nodeReceiver.
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2481
        classOrNil isNil ifTrue:[
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2482
            classesFromAssignmentsToReceiver size == 1 ifTrue:[
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2483
                classOrNil := classesFromAssignmentsToReceiver anElement
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2484
            ].
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2485
        ].
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2486
        classOrNil notNil ifTrue:[
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2487
            selectorsImplementedInClass := classOrNil selectors.
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2488
"/            selectorsImplementedInClass := Set new.
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2489
"/            classOrNil withAllSuperclassesDo:[:cls |
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2490
"/                cls theNonMetaclass ~~ Object ifTrue:[
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2491
"/                    selectorsImplementedInClass addAll:cls selectors.
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2492
"/                ]
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2493
"/            ]    
4936
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2494
        ]
5606
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  2495
    ].
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  2496
    
4936
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2497
    selectorsImplementedInClass notNil ifTrue:[
5528
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  2498
        (parentSelector notNil and:[parentSelector includes:$:]) ifTrue:[
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  2499
            selectorsImplementedInClass := selectorsImplementedInClass reject:[:sel | sel isKeywordSelector].
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  2500
        ].
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  2501
        
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2502
        "/ the one's implemented in the class itself are moved to the top of the list.
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2503
        allBest := self 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2504
                    splitSelectorList:allBest 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2505
                    by:[:sel | selectorsImplementedInClass includes:sel].
4936
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  2506
    ].
5042
151b3c1bf4d1 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5041
diff changeset
  2507
    otherMessagesToReceiver "selectorsSentInCode" notNil ifTrue:[
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2508
        "/ the one's already sent in the code are moved to the top of the list.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2509
        "/ trouble is: parser bails out on error, so most of the time, we only see
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2510
        "/ selectors sent previously. sigh.
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2511
        allBest := self 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2512
                    splitSelectorList:allBest 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2513
                    by:[:sel | otherMessagesToReceiver "selectorsSentInCode" includes:sel].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2514
    ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2515
 
5528
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  2516
    (parentSelector notNil and:[parentSelector includes:$:]) ifTrue:[
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  2517
        allBest := self 
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  2518
                    splitSelectorList:allBest 
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  2519
                    by:[:sel | sel startsWith:parentSelector].
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  2520
    ].
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  2521
    
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2522
"/ this makes it very slow
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2523
"/false ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2524
"/    srchClass notNil ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2525
"/        implClass := srchClass whichClassIncludesSelector:best.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2526
"/    ] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2527
"/        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
  2528
"/        implClass size == 1 ifTrue:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2529
"/            implClass := implClass first.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2530
"/        ] ifFalse:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2531
"/            implClass := nil
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2532
"/        ]
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2533
"/    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2534
"/
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2535
"/    info := best storeString.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2536
"/    implClass notNil ifTrue:[
6022
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
  2537
"/        info := implClass name , ' » ' , info.
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2538
"/    ].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2539
"/    self information:info.
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2540
"/].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2541
 
5528
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  2542
    (parentSelector notNil and:[parentSelector includes:$:]) ifTrue:[
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  2543
        "/ the one's which are a prefix are moved towards the top of the list
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  2544
        allBest := self splitSelectorList:allBest 
5613
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  2545
                        by:[:sel | sel notNil and:[sel asLowercase startsWith:lcSelectorWithoutColon]].
5528
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  2546
    ].
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  2547
    
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2548
    "/ heuristic hack:
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2549
    "/ 'i' and 'w' generate lists in which ifXXX / whileXXX are not at the top of the list.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2550
    "/ we know, that those are most often wanted!!
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2551
    selector size <= 2 ifTrue:[
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2552
        allBest := self 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2553
                    splitSelectorList:allBest 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2554
                    by:[:sel | 
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2555
                        #(ifTrue: ifFalse: isNil notNil whileTrue whileFalse) includes:sel
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2556
                    ].
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2557
    ]. 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2558
5606
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  2559
    "/ sort again: prefixes must always come before
5613
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  2560
    allBest sortBySelector:#size.
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  2561
    self sortSelectors:allBest forSelector:selectorWithoutColon lcSelector:lcSelectorWithoutColon.
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  2562
    "/ self sortUsefulSelectorsIn:allBest. "/cosmetics
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2563
5528
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  2564
    (parentSelector notNil and:[parentSelector includes:$:]) ifTrue:[
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  2565
        allBest := (allBest 
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  2566
                        select:[:sel | sel startsWith:parentSelector]
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  2567
                        thenCollect:[:sel | sel copyFrom:(parentSelector lastIndexOf:$:)+1])
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  2568
                    ,
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  2569
                    (allBest 
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  2570
                        reject:[:sel | sel startsWith:parentSelector]).
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  2571
    ].
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  2572
    
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2573
    "/ parenthesizers always at the end.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2574
    bestWithParenthesis notEmptyOrNil ifTrue:[ 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2575
        allBest := allBest , bestWithParenthesis.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2576
    ].
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2577
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2578
    "/ self at:1 put:#foo
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2579
    "/ Array new:10
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2580
    offerParenthisationAroundNode notNil ifTrue:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2581
        allBest := allBest copyWith:( '(',selector,')' ).
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2582
        parenthesisAroundIndex := allBest size.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2583
    ].
5071
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2584
    offerValueInsertion ifTrue:[
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2585
        allBest := allBest copyWith:( '... ',(valueToInsert contractTo:30),valueInfo). 
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2586
        valueToInsertIndex := allBest size.
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2587
    ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2588
 
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2589
    editAction :=
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2590
        [:index |
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2591
            |crsrPos chosen parenthesisToInsert action|
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2592
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2593
            action := nil.
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2594
            crsrPos := codeView characterPositionOfCursor.
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2595
            chosen := allBest at:index.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2596
 
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2597
            chosen ~= selector ifTrue:[
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2598
                (bestWithParenthesis notNil and:[bestWithParenthesis includes:chosen]) ifTrue:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2599
                    "/ for input like: 
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2600
                    "/   chosen at: 10 if
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2601
                    "/ put parenthesis around, and add ifTrue/ifFalse
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2602
                    "/ i.e.:   (chosen at:10) ifTrue:[]
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2603
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2604
                    "/ for input like: 
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2605
                    "/   a > 10 wh
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2606
                    "/ put brackets around and add whileTrue/whileFalse
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2607
                    "/ i.e.:   [a > 10] whileTrue:[]
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2608
                    parenthesisToInsert := chosen first == $( ifTrue:'()' ifFalse:'[]'.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2609
                    chosen := (chosen copyFrom:(chosen lastIndexOf:parenthesisToInsert second)+1) withoutSeparators.
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2610
                ] ifFalse:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2611
                    (offerParenthisationAroundNode notNil and:[index = parenthesisAroundIndex]) ifTrue:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2612
                        "/ for input like: 
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2613
                        "/      Array new:10
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2614
                        "/ put parenthesis around.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2615
                        "/ i.e.:   (Array new:10)
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2616
                        action :=
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2617
                            [
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2618
                                codeView insertString:'(' atCharacterPosition:offerParenthisationAroundNode start.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2619
                                codeView insertString:')' atCharacterPosition:offerParenthisationAroundNode stop+2.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2620
                                codeView cursorToCharacterPosition:(offerParenthisationAroundNode stop+2); cursorRight.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2621
                            ].
5071
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2622
                    ] ifFalse:[
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2623
                        (offerValueInsertion and:[index = valueToInsertIndex]) ifTrue:[
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2624
                            "/ for input like: 
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2625
                            "/      foo == 
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2626
                            "/ insert a value
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2627
                            "/ i.e.:   foo == #someSymbol
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2628
                            action :=
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2629
                                [
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2630
                                    codeView characterBeforeCursor isSeparator ifFalse:[
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2631
                                        codeView insertStringAtCursor:' '.
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2632
                                    ].    
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2633
                                    codeView insertStringAtCursor:valueToInsert.
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2634
                                    "/ codeView cursorRight.
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2635
                                ].
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2636
                        ]
976ed2a22e27 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5070
diff changeset
  2637
                    ].    
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2638
                ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2639
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2640
                action isNil ifTrue:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2641
                    numArgs := chosen numArgs.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2642
                    (bestSelectors2 notEmptyOrNil and:[bestSelectors2 includes:chosen]) ifTrue:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2643
                        selectorParts := parentNode selectorParts , node selectorParts.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2644
                    ] ifFalse:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2645
                        selectorParts := node selectorParts.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2646
                    ].
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2647
                    nSelParts := selectorParts size.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2648
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2649
                    newParts := chosen asCollectionOfSubstringsSeparatedBy:$:.
6013
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  2650
                    newParts := newParts select:[:part | part size ~~ 0].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2651
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2652
                    action :=
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2653
                        [
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2654
                            |positionOfFirstArg newCursorPosition stop checkForArgumentTemplates
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2655
                             newPart oldPartialToken start|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2656
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2657
                            checkForArgumentTemplates := (selector isUnarySelector and:[chosen isKeywordSelector]).
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2658
                            numArgs > nSelParts ifTrue:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2659
                                "/ new selector has more arguments; append them
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2660
                                stop := selectorParts last stop.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2661
                                codeView deleteFromCharacterPosition:stop+1 to:crsrPos-1.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2662
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2663
                                "/ append the rest ...
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2664
                                (numArgs min:newParts size) downTo:(nSelParts+1) do:[:idx |
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2665
                                    |newPart|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2666
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2667
                                    newPart := newParts at:idx.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2668
                                    newPart := newPart , ':'.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2669
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2670
                                    (codeView characterAtCharacterPosition:stop) == $: ifFalse:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2671
                                        newPart := ':' , newPart.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2672
                                    ].
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2673
                                    newPart := (codeView characterAtCharacterPosition:stop) asString , newPart.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2674
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2675
                                    codeView replaceFromCharacterPosition:stop to:stop with:newPart.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2676
                                    "/ remember the leftMost replacement's end as new cursor position
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2677
                                    newCursorPosition := stop + newPart size
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2678
                                ].
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2679
                                checkForArgumentTemplates := true.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2680
                            ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2681
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2682
                            "/ replace existing parts
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2683
                            (nSelParts min:newParts size) downTo:1 do:[:idx |
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2684
                                |skipColon|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2685
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2686
                                skipColon := 0.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2687
                                newPart := newParts at:idx.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2688
                                oldPartialToken := selectorParts at:idx.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2689
                                start := oldPartialToken start.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2690
                                stop := oldPartialToken stop.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2691
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2692
                                (chosen endsWith:$:) ifTrue:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2693
                                    (codeView characterAtCharacterPosition:stop+1) == $: ifFalse:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2694
                                        newPart := newPart , ':'.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2695
                                    ] ifTrue:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2696
                                        skipColon := 1.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2697
                                    ]
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2698
                                ] ifFalse:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2699
                                    (codeView characterAtCharacterPosition:stop) == $: ifTrue:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2700
                                        newPart := newPart , ':'
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2701
                                    ] ifFalse:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2702
                                        |nextChar|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2703
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2704
                                        nextChar := codeView characterAtCharacterPosition:stop+1.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2705
                                        nextChar isSeparator ifFalse:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2706
                                            nextChar == $. ifFalse:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2707
                                                newPart := newPart , ' '
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2708
                                            ].
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2709
                                        ]
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2710
                                    ]
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2711
            "/                            codeView replaceFromCharacterPosition:start to:stop with:(newPart , ':').
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2712
            "/                        ] ifFalse:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2713
            "/                            codeView replaceFromCharacterPosition:start to:stop with:newPart.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2714
                                ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2715
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2716
                                oldPartialToken value ~= newPart ifTrue:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2717
                                    codeView replaceFromCharacterPosition:start to:stop with:newPart.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2718
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2719
                                    oldLen := stop - start + 1.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2720
                                    newLen := newPart size.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2721
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2722
                                    "/ codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2723
                                    "/ remember the leftMost replacement's end as new cursor position
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2724
                                    newCursorPosition := start + newPart size + skipColon. "/ (newLen-oldLen) + 1.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2725
                                    "/ codeView cursorToCharacterPosition:newCursorPosition.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2726
                                ].
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2727
                            ].
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2728
                            newCursorPosition notNil ifTrue:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2729
                                codeView cursorToCharacterPosition:newCursorPosition-1.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2730
                                codeView cursorRight.  "/ avoid going to the next line !!
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2731
                            ].
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2732
                            codeView dontReplaceSelectionOnInput.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2733
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2734
                            checkForArgumentTemplates ifTrue:[
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2735
                                "/ add opening brackets, etc.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2736
                                self insertAdditonalStuffAfterSelector:chosen.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2737
                            ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2738
                            parenthesisToInsert notNil ifTrue:[
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2739
                                |sav pos|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2740
 
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2741
                                sav := codeView characterPositionOfCursor-1.
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2742
                                "/ check if already parenthized
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2743
                                parentNodeToParenthesize hasParentheses ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2744
                                    pos := parentNodeToParenthesize parentheses first first.
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2745
                                    codeView selectFromCharacterPosition:pos to:pos.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2746
                                    codeView replaceSelectionBy:(parenthesisToInsert copyFirst:1) asString.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2747
 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2748
                                    pos := parentNodeToParenthesize parentheses first last.
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2749
                                    codeView selectFromCharacterPosition:pos to:pos.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2750
                                    codeView replaceSelectionBy:(parenthesisToInsert copyLast:1) asString.
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2751
                                    codeView cursorToCharacterPosition:sav; cursorRight
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2752
                                ] ifFalse:[
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2753
                                    codeView insertString:(parenthesisToInsert copyLast:1) atCharacterPosition:node receiver stop+1.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2754
                                    codeView insertString:(parenthesisToInsert copyFirst:1) atCharacterPosition:parentNodeToParenthesize start.
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2755
                                    codeView cursorToCharacterPosition:sav+2; cursorRight
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2756
                                ].
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2757
                            ].
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2758
                        ].
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2759
                    ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2760
 
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2761
                codeView
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2762
                    undoableDo:action
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  2763
                    info:'Completion'.
4610
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2764
            ].
6e07eb8f8e8b class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4592
diff changeset
  2765
        ].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2766
    actionBlock value:allBest value:editAction value:nil.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2767
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2768
    "Created: / 10-11-2006 / 13:18:27 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2769
    "Modified: / 16-02-2010 / 10:33:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
5613
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  2770
    "Modified: / 30-09-2017 / 14:12:47 / cg"
6013
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  2771
    "Modified: / 01-03-2019 / 14:52:35 / Claus Gittinger"
6036
171e12f06b70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6022
diff changeset
  2772
    "Modified (comment): / 18-03-2019 / 11:22:48 / Claus Gittinger"
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2773
!
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2774
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2775
codeCompletionForMessageTo:node into:actionBlock
5106
5303d78eb69a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5104
diff changeset
  2776
    "find good suggestions for a message send to node, with no input yet.
5303d78eb69a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5104
diff changeset
  2777
     I.e. right after a receiver (w.o. any input yet)"
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2778
    
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2779
    |knownClass suggestions selectorsImplementedInClass mostUseful editActions pos|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2780
 
5606
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  2781
    (knownClass := self classOfNode:node) isEmptyOrNil ifTrue:[
5621
bc187db92ab4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5613
diff changeset
  2782
        "/ self breakPoint:#cg.
5113
6a5ae22ee501 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5112
diff changeset
  2783
        "/ self classOfNode:node.
5106
5303d78eb69a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5104
diff changeset
  2784
        ^ self
5303d78eb69a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5104
diff changeset
  2785
    ].
5303d78eb69a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5104
diff changeset
  2786
    
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  2787
    Verbose == true ifTrue:[ 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  2788
        Transcript show:node; show:' -> '; showCR:knownClass.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  2789
    ].    
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2790
    selectorsImplementedInClass := Set new.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2791
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2792
    knownClass withAllSuperclassesDo:[:cls |
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2793
        cls ~~ Object ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2794
            selectorsImplementedInClass addAll:cls selectors.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2795
        ]    
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2796
    ].
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2797
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2798
    knownClass isMeta ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2799
        selectorsImplementedInClass := 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2800
            selectorsImplementedInClass reject:[:sel |
6022
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
  2801
                |mthd cat|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2802
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2803
                mthd := knownClass lookupMethodFor:sel.
6022
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
  2804
                mthd notNil 
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
  2805
                  and:[(cat := mthd category) notNil 
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
  2806
                  and:[(cat startsWith: 'documentation')]]
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2807
            ].
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2808
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2809
        knownClass theNonMetaclass isAbstract ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2810
            mostUseful := selectorsImplementedInClass select:[:sel |
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2811
                            knownClass implements:sel
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2812
                          ]
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2813
        ] ifFalse:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2814
            mostUseful := selectorsImplementedInClass select:[:sel |
6022
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
  2815
                                |mthd cat|
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2816
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2817
                                mthd := knownClass lookupMethodFor:sel.
6022
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
  2818
                                mthd notNil 
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
  2819
                                  and:[(cat := mthd category) notNil 
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
  2820
                                  and:[cat startsWith: 'instance']]
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2821
                          ].
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2822
        ]
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2823
    ] ifFalse:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2824
        mostUseful := 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2825
            #(
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2826
                "/ blocks
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2827
                ifTrue: ifFalse: whileTrue: whileFalse: on:do: ensure: 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2828
                whileTrue whileFalse loop
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2829
                "/ any
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2830
                isNil notNil isEmpty notEmpty 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2831
            ).
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2832
    ].
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2833
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2834
    mostUseful notNil ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2835
        suggestions := 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2836
            (selectorsImplementedInClass select:[:sel | mostUseful includes:sel]) asNewOrderedCollection sort
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2837
            ,
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2838
            (selectorsImplementedInClass reject:[:sel | mostUseful includes:sel]) asNewOrderedCollection sort.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2839
    ] ifFalse:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2840
        suggestions := selectorsImplementedInClass asNewOrderedCollection sort.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2841
    ].
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2842
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  2843
    suggestions := suggestions reject:[:sel | sel first == $_].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2844
    self sortUsefulSelectorsIn:suggestions. "/cosmetics
5041
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  2845
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  2846
    pos := codeView characterPositionOfCursor.
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2847
    editActions := suggestions collect:[:word |
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2848
                        self editActionToReplaceCodeFrom:pos to:pos-1 by:word.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2849
                   ].                
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  2850
    actionBlock value:suggestions value:editActions value:nil.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2851
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  2852
    "Created: / 01-05-2016 / 17:01:21 / cg"
5621
bc187db92ab4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5613
diff changeset
  2853
    "Modified: / 10-10-2017 / 16:57:21 / cg"
6022
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
  2854
    "Modified: / 03-03-2019 / 22:41:42 / Claus Gittinger"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2855
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2856
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2857
codeCompletionForMethodSpec:node
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2858
    "completion in a method's selector pattern"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2859
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2860
    self
5312
a16f68b2aba1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5285
diff changeset
  2861
        codeCompletionForMethodSpec:node
5613
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  2862
        into:[:suggestions :action :whatIsIt |
5312
a16f68b2aba1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5285
diff changeset
  2863
a16f68b2aba1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5285
diff changeset
  2864
            |chosen|
a16f68b2aba1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5285
diff changeset
  2865
a16f68b2aba1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5285
diff changeset
  2866
            chosen := self askUserForCompletion:whatIsIt for:codeView
a16f68b2aba1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5285
diff changeset
  2867
                           at:node start from:suggestions.
a16f68b2aba1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5285
diff changeset
  2868
            chosen notNil ifTrue:[
a16f68b2aba1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5285
diff changeset
  2869
                action value:(suggestions indexOf:chosen)
a16f68b2aba1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5285
diff changeset
  2870
            ].
a16f68b2aba1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5285
diff changeset
  2871
        ].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2872
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2873
"/    |crsrPos
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2874
"/     selectorSoFar matchingSelectors
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2875
"/     selectors distances best rest
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2876
"/     allExistingMethods nameBag namesByCount selectors1 selectors2|
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2877
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2878
"/    crsrPos := codeView characterPositionOfCursor - 1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2879
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2880
"/    selectorSoFar := ''.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2881
"/    node selectorParts doWithIndex:[:partToken :argNr|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2882
"/        |part|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2883
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2884
"/        part := partToken value.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2885
"/        selectorSoFar := selectorSoFar , part.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2886
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2887
"/        (crsrPos >= partToken start
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2888
"/        and:[crsrPos <= partToken stop]) ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2889
"/            (classOrNil notNil and:[classOrNil isMeta]) ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2890
"/                matchingSelectors := Smalltalk allClasses
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2891
"/                                    inject:(Set new)
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2892
"/                                    into:[:theSet :eachClass |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2893
"/                                        |md|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2894
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2895
"/                                        md := eachClass theMetaclass methodDictionary.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2896
"/                                        theSet addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]).
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2897
"/                                        theSet.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2898
"/                                    ].
5312
a16f68b2aba1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5285
diff changeset
  2899
"/                "/ don't forget the stuff in the class-line
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2900
"/                Metaclass withAllSuperclassesDo:[:cls |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2901
"/                    matchingSelectors addAll:(cls methodDictionary keys select:[:sel |sel startsWith:selectorSoFar]).
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2902
"/                ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2903
"/            ] ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2904
"/                matchingSelectors := Smalltalk allClasses
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2905
"/                                    inject:(Set new)
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2906
"/                                    into:[:theSet :eachClass |
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2907
"/                                        |md|
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2908
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2909
"/                                        md := eachClass theNonMetaclass methodDictionary.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2910
"/                                        theSet addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]).
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2911
"/                                        theSet.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2912
"/                                    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2913
"/            ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2914
"/            selectors := matchingSelectors asOrderedCollection.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2915
"/
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2916
"/            "/ 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
  2917
"/            (selectors size == 1
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2918
"/            and:[selectors first = selectorSoFar]) ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2919
"/                selectorSoFar numArgs == 0 ifTrue:[ ^ self ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2920
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2921
"/                allExistingMethods := (Smalltalk allImplementorsOf:selectorSoFar asSymbol)
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2922
"/                                        collect:[:cls | cls compiledMethodAt:selectorSoFar asSymbol].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2923
"/                nameBag := Bag new.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2924
"/                allExistingMethods do:[:eachMethod | nameBag addAll:(eachMethod methodArgNames ? #())].
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2925
"/                namesByCount := nameBag valuesAndCounts sort:[:a :b | a value < b value].
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2926
"/                "/ take the one which occurs most often
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2927
"/                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
  2928
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2929
"/                codeView
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2930
"/                    undoableDo:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2931
"/                        (crsrPos+1) >= codeView contents size ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2932
"/                            codeView paste:best.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2933
"/                        ] ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2934
"/                            codeView insertString:best atCharacterPosition:crsrPos+1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2935
"/                        ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2936
"/                    ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2937
"/                    info:'completion'.
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2938
"/                codeView cursorToCharacterPosition:(crsrPos + best size - 1).
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2939
"/            ] ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2940
"/                "the ones implemented in superclasses are shown first"
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2941
"/                classOrNil notNil ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2942
"/                    selectors1 := selectors select:[:sel | classOrNil respondsTo:sel].  "/ in super
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2943
"/                    selectors2 := selectors reject:[:sel | selectors1 includes:sel ].   "/ not in super
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2944
"/                ] ifFalse:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2945
"/                    selectors1 := selectors
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2946
"/                ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2947
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2948
"/                distances := selectors1 collect:[:each | each spellAgainst:selectorSoFar].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2949
"/                distances sortWith:selectors1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2950
"/                selectors1 reverse.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2951
"/                selectors := selectors1.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2952
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2953
"/                selectors2 notEmptyOrNil ifTrue:[
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2954
"/                    distances := selectors2 collect:[:each | each spellAgainst:selectorSoFar].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2955
"/                    distances sortWith:selectors2.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2956
"/                    selectors2 reverse.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2957
"/                    selectors1 := selectors1 collect:[:sel | sel allBold].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2958
"/                    selectors := selectors1,selectors2.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2959
"/                ].
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2960
"/
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2961
"/                best := self askUserForCompletion:'selector' for:codeView at:(node start) from:selectors.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2962
"/                best isNil ifTrue:[^ self].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2963
"/
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2964
"/                rest := best copyFrom:selectorSoFar size.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2965
"/                codeView
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2966
"/                    undoableDo:[
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2967
"/                        codeView
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2968
"/                            replaceFromCharacterPosition:crsrPos+1
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2969
"/                            to:crsrPos+1
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2970
"/                            with:rest
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2971
"/                    ]
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2972
"/                    info:'Completion'.
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2973
"/                codeView cursorToCharacterPosition:(crsrPos+1 + rest size - 1).
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2974
"/            ].
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2975
"/            codeView cursorRight. "/ kludge to make it visible
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2976
"/        ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2977
"/    ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2978
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2979
    "Modified: / 04-07-2006 / 18:48:26 / fm"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2980
    "Created: / 10-11-2006 / 13:46:44 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2981
    "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
  2982
    "Modified: / 01-06-2012 / 20:31:36 / cg"
5613
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  2983
    "Modified (format): / 30-09-2017 / 12:58:32 / cg"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2984
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2985
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  2986
codeCompletionForMethodSpec:node into:actionBlock
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2987
    "completion in a method's selector pattern"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2988
4370
2569507c08b9 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4369
diff changeset
  2989
    |crsrPos crsrLine crsrCol
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2990
     selectorSoFar matchingSelectors
5146
1bc2c5c6fc91 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 5143
diff changeset
  2991
     selectors allExistingMethods nameBag namesByCount 
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2992
     allSelectors
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2993
     selectorsForIsXXXTests selectorsSentInClass selectorsImplementedInSuper 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2994
     editAction editActionForArg argNames selectorsForVars
5637
c37992ea83d4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5633
diff changeset
  2995
     selectorTypedSoFar selectorTypedSoFarLC addIfNotYetImplemented alreadyOK processMenu|
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2996
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  2997
    allSelectors := Set new.
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2998
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  2999
    "/ Transcript showCR:'m'.
4370
2569507c08b9 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4369
diff changeset
  3000
    crsrLine := codeView cursorLine.
2569507c08b9 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4369
diff changeset
  3001
    crsrCol := codeView cursorCol.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3002
    crsrPos := codeView characterPositionOfCursor - 1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3003
4691
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  3004
    selectorTypedSoFar := node selector.
5637
c37992ea83d4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5633
diff changeset
  3005
    selectorTypedSoFarLC := selectorTypedSoFar asLowercase.
c37992ea83d4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5633
diff changeset
  3006
    
4691
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  3007
    selectorTypedSoFar isUnarySelector ifTrue:[
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3008
        "/ user has just begun to edit a selector.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3009
        "/ 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
  3010
        classOrNil notNil ifTrue:[
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3011
            selectorsForVars := Set new.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3012
            selectorsImplementedInSuper := Set new.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3013
            selectorsSentInClass := Set new.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3014
            selectorsForIsXXXTests := Set new.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3015
            
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3016
            addIfNotYetImplemented :=
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3017
                [:list :sel |
5738
59d8e9757a0f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5714
diff changeset
  3018
                    "/ sel = 'max:' ifTrue:[self breakPoint:#cg].
5637
c37992ea83d4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5633
diff changeset
  3019
                    (sel sameAs: selectorTypedSoFar) ifFalse:[    
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3020
                        (allSelectors includes:sel) ifFalse:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3021
                            (classOrNil implements:sel asSymbol) ifFalse:[ 
5598
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3022
                                list add:sel.
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3023
                                allSelectors add:sel.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3024
                            ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3025
                        ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3026
                    ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3027
                ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3028
                
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3029
            classOrNil instVarNames do:[:nm |
4691
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  3030
                (nm startsWith:selectorTypedSoFar) ifTrue:[
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3031
                    addIfNotYetImplemented value:selectorsForVars value:nm.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3032
                    addIfNotYetImplemented value:selectorsForVars value:(nm,':').
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3033
                 ]
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3034
            ].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3035
            classOrNil isMeta ifTrue:[
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3036
                classOrNil theNonMetaclass classVarNames do:[:nm |
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3037
                    |nmSel|
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3038
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3039
                    nmSel := nm asLowercaseFirst.
5637
c37992ea83d4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5633
diff changeset
  3040
                    (nmSel startsWith:selectorTypedSoFarLC) ifTrue:[
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3041
                        addIfNotYetImplemented value:selectorsForVars value:nmSel.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3042
                        addIfNotYetImplemented value:selectorsForVars value:(nmSel,':').
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3043
                    ]
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3044
                ].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3045
            ] ifFalse:[
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3046
                "/ isXXX ?
4691
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  3047
                (('is',classOrNil nameWithoutPrefix) startsWith:selectorTypedSoFar ) ifTrue:[
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3048
                    addIfNotYetImplemented value:selectorsForIsXXXTests value:('is',classOrNil nameWithoutPrefix).
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3049
                ].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3050
            ].
4691
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  3051
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  3052
            "/ and also messages sent by the class itself
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  3053
            classOrNil methodsDo:[:m |
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  3054
                m messagesSentToSelf do:[:sel |
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  3055
                    (sel startsWith:selectorTypedSoFar) ifTrue:[
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3056
                        addIfNotYetImplemented value:selectorsSentInClass value:sel.
4691
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  3057
                    ]                     
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  3058
                ]
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  3059
            ].
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  3060
            classOrNil isMeta ifFalse:[
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  3061
                classOrNil theMetaclass methodsDo:[:m |
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  3062
                    m messagesSent do:[:sel |
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  3063
                        (sel startsWith:selectorTypedSoFar) ifTrue:[
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3064
                            addIfNotYetImplemented value:selectorsSentInClass value:sel.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3065
                        ]                     
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3066
                    ]                     
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3067
                ]
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3068
            ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3069
            "/ and also messages implemented by superclasses (except Object)
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3070
            classOrNil allSuperclassesDo:[:eachSuperclass |
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3071
                eachSuperclass ~~ Object ifTrue:[
5462
6a7b577cd2b9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5453
diff changeset
  3072
                    eachSuperclass selectorsDo:[:sel |
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3073
                        (sel startsWith:selectorTypedSoFar) ifTrue:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3074
                            addIfNotYetImplemented value:selectorsImplementedInSuper value:sel.
4691
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  3075
                        ]                     
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  3076
                    ]                     
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  3077
                ]
b8baa7c905ef class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4689
diff changeset
  3078
            ].
5598
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3079
            "/ if on the instance side, and the class side has menu- or windowspecs,
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3080
            "/ also add messages named as callbacks or aspects
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3081
            (classOrNil theNonMetaclass inheritsFrom:ApplicationModel) ifTrue:[
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3082
                processMenu :=  
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3083
                    [:menu |
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3084
                        menu itemsDo:[:item |
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3085
                            |sel subMenu|
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3086
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3087
                            (sel := item choice) notNil ifTrue:[
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3088
                                addIfNotYetImplemented value:selectorsSentInClass value:sel
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3089
                            ].    
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3090
                            (sel := item itemValue) notNil ifTrue:[
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3091
                                addIfNotYetImplemented value:selectorsSentInClass value:sel
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3092
                            ].    
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3093
                            (sel := item submenuChannel) notNil ifTrue:[
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3094
                                addIfNotYetImplemented value:selectorsSentInClass value:sel
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3095
                            ].    
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3096
                            (subMenu := item submenu) notNil ifTrue:[
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3097
                                processMenu value:subMenu
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3098
                            ].    
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3099
                        ].    
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3100
                    ].    
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3101
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3102
                classOrNil withAllSuperclassesDo:[:eachSuperclass |
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3103
                    eachSuperclass theMetaclass methodDictionary keysAndValuesDo:[:sel :mthd |
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3104
                        |spec bodyNode retVal specArray menu| 
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3105
                        
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3106
                        (mthd hasMenuResource) ifTrue:[
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3107
                            bodyNode := mthd parseTree body.
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3108
                            bodyNode lastIsReturn ifTrue:[
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3109
                                (retVal := bodyNode statements last value) isLiteralArray ifTrue:[
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3110
                                    specArray := retVal value.
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3111
                                    menu := specArray decodeAsLiteralArray.
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3112
                                    processMenu value:menu.    
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3113
                                ].
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3114
                            ].
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3115
                        ].    
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3116
                        (mthd hasCanvasResource) ifTrue:[
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3117
                            bodyNode := mthd parseTree body.
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3118
                            bodyNode lastIsReturn ifTrue:[
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3119
                                (retVal := bodyNode statements last value) isLiteralArray ifTrue:[
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3120
                                    specArray := retVal value.
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3121
                                    spec := specArray decodeAsLiteralArray.
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3122
                                    spec aspectSelectors do:[:sel | addIfNotYetImplemented value:selectorsSentInClass value:sel].
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3123
                                    spec valueSelectors do:[:sel | addIfNotYetImplemented value:selectorsSentInClass value:sel].
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3124
                                    spec actionSelectors do:[:sel | addIfNotYetImplemented value:selectorsSentInClass value:sel].
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3125
                                ].
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3126
                            ].
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3127
                        ].
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3128
                    ].    
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3129
                    eachSuperclass selectorsDo:[:sel |
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3130
                        (sel startsWith:selectorTypedSoFar) ifTrue:[
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3131
                            addIfNotYetImplemented value:selectorsImplementedInSuper value:sel.
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3132
                        ]                     
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3133
                    ]                     
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3134
                ]
5b69ed53ef4b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  3135
            ].
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3136
        ].
4371
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  3137
    ].
95c3d2ba35d5 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4370
diff changeset
  3138
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3139
    selectorSoFar := ''.
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3140
    matchingSelectors := Set new.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3141
    
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3142
    node selectorParts doWithIndex:[:partToken :argNr|
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3143
        |part|
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3144
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3145
        part := partToken value.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3146
        selectorSoFar := selectorSoFar , part.
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3147
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3148
        (crsrPos >= partToken start 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3149
            and:[crsrPos <= partToken stop
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3150
                 or:[ (crsrPos == (partToken stop+1))
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3151
                      and:[codeView characterBeforeCursor == Character space]] ]
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3152
        ) ifTrue:[
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3153
            (classOrNil notNil and:[classOrNil isMeta]) ifTrue:[
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3154
                Smalltalk 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3155
                    allClassesDo:[:eachClass |
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3156
                        |md|
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3157
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3158
                        md := eachClass theMetaclass methodDictionary.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3159
                        matchingSelectors addAll:(md keys 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3160
                                                    select:[:sel |sel startsWith:selectorSoFar]).
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3161
                    ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3162
                "/ do not forget the stuff in the class-line
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3163
                Metaclass withAllSuperclassesDo:[:cls |
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3164
                    matchingSelectors addAll:(cls methodDictionary keys 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3165
                                                select:[:sel |sel startsWith:selectorSoFar]).
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3166
                ].
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3167
            ] ifFalse:[
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3168
                Smalltalk 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3169
                    allClassesDo:[:eachClass |
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3170
                        |md|
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3171
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3172
                        md := eachClass theNonMetaclass methodDictionary.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3173
                        matchingSelectors addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]).
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3174
                    ].
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3175
            ].
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3176
        ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3177
    ].  
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3178
    alreadyOK := matchingSelectors includes:selectorTypedSoFar.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3179
    matchingSelectors remove:selectorTypedSoFar ifAbsent:[].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3180
    
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3181
    selectors := Set new.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3182
            
5637
c37992ea83d4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5633
diff changeset
  3183
    selectorsForVars notNil ifTrue:[ 
c37992ea83d4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5633
diff changeset
  3184
        selectors addAll:selectorsForVars 
c37992ea83d4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5633
diff changeset
  3185
    ].
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3186
    selectorsSentInClass notNil ifTrue:[ selectors addAll:selectorsSentInClass ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3187
    selectorsImplementedInSuper notNil ifTrue:[ selectors addAll:selectorsImplementedInSuper ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3188
    selectorsForIsXXXTests notNil ifTrue:[ selectors addAll:selectorsForIsXXXTests ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3189
        
5637
c37992ea83d4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5633
diff changeset
  3190
    (selectors count:[:sel | sel asLowercase startsWith:selectorTypedSoFarLC]) == 0 ifTrue:[
c37992ea83d4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5633
diff changeset
  3191
        selectors addAll:matchingSelectors.
c37992ea83d4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5633
diff changeset
  3192
    ].    
c37992ea83d4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5633
diff changeset
  3193
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3194
    selectors := selectors asOrderedCollection.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3195
    selectors sort:[:a :b | a size < b size].
5637
c37992ea83d4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5633
diff changeset
  3196
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3197
    selectorsSentInClass notEmptyOrNil ifTrue:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3198
        selectors := self 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3199
                        splitSelectorList:selectors 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3200
                        by:[:sel | selectorsSentInClass includes:sel].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3201
    ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3202
    selectorsImplementedInSuper notEmptyOrNil ifTrue:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3203
        selectors := self 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3204
                        splitSelectorList:selectors 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3205
                        by:[:sel | selectorsImplementedInSuper includes:sel].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3206
    ].
5637
c37992ea83d4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5633
diff changeset
  3207
c37992ea83d4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5633
diff changeset
  3208
    selectors := self 
c37992ea83d4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5633
diff changeset
  3209
                    splitSelectorList:selectors 
c37992ea83d4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5633
diff changeset
  3210
                    by:[:sel | sel asLowercase startsWith:selectorTypedSoFarLC].
c37992ea83d4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5633
diff changeset
  3211
c37992ea83d4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5633
diff changeset
  3212
    selectorsForVars notEmptyOrNil ifTrue:[
c37992ea83d4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5633
diff changeset
  3213
        selectors := self 
c37992ea83d4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5633
diff changeset
  3214
                        splitSelectorList:selectors 
c37992ea83d4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5633
diff changeset
  3215
                        by:[:sel | selectorsForVars includes:sel].
c37992ea83d4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5633
diff changeset
  3216
    ].
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3217
    selectorsForIsXXXTests notEmptyOrNil ifTrue:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3218
        selectors := self 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3219
                        splitSelectorList:selectors 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3220
                        by:[:sel | selectorsForIsXXXTests includes:sel].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3221
    ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3222
    
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3223
    selectors size > 100 ifTrue:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3224
        selectors := selectors copyTo:100.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3225
    ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3226
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3227
    "/ if there is only one, and user has already entered it, 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3228
    "/ he might want to complete the argument-name
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3229
    (alreadyOK and:[selectorSoFar numArgs > 0]) ifTrue:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3230
        allExistingMethods := (Smalltalk allImplementorsOf:selectorSoFar asSymbol)
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3231
                                    collect:[:cls | cls compiledMethodAt:selectorSoFar asSymbol].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3232
        nameBag := Bag new.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3233
        allExistingMethods do:[:eachMethod | nameBag addAll:(eachMethod methodArgNames ? #())].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3234
        namesByCount := nameBag valuesAndCounts sort:[:a :b | a value < b value].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3235
        namesByCount := namesByCount copyToMax:5.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3236
        
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3237
        "/ take the one which occurs most often
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3238
        argNames := (namesByCount collect:[:a | a key]).
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3239
        argNames do:[:eachArgName |
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3240
            selectors add:('%1 %2 %3' 
5089
9592bdeeff69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5086
diff changeset
  3241
                            bindWith:(selectorSoFar withColor:Color darkGrey) 
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3242
                            with:eachArgName
5089
9592bdeeff69 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5086
diff changeset
  3243
                            with:('(argument)' allItalic withColor:Color darkGrey)).
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3244
        ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3245
        
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3246
        editActionForArg :=
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3247
                [:chosenItem |
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3248
                    |chosenName|
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3249
                    
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3250
                    chosenName := chosenItem 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3251
                                    copyFrom:(selectorSoFar size+2)
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3252
                                    to:(chosenItem indexOfSeparatorStartingAt:selectorSoFar size+2)-1.
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3253
                    codeView
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3254
                        undoableDo:[
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3255
                            (crsrPos+1) >= codeView contents size ifTrue:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3256
                                codeView paste:chosenName.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3257
                                codeView cursorToCharacterPosition:(crsrPos + chosenName size - 1).
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3258
                            ] ifFalse:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3259
                                codeView cursorToCharacterPosition:crsrPos.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3260
                                codeView cursorRight.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3261
                                codeView insertStringAtCursor:chosenName.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3262
                                codeView selectFromCharacterPosition:crsrPos+1 to:crsrPos+1+chosenName size-1.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3263
                                codeView dontReplaceSelectionOnInput
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3264
                            ].
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3265
                        ]
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3266
                        info:'argname completion'.
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3267
                ].
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3268
    ].            
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3269
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3270
    "/ no, still more possibilities for the selector.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3271
    "/ the ones implemented in superclasses are shown first.
5146
1bc2c5c6fc91 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 5143
diff changeset
  3272
    (classOrNil notNil and:[classOrNil superclass notNil]) ifTrue:[
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3273
        selectors := self 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3274
                        splitSelectorList:selectors 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3275
                        by:[:sel | classOrNil superclass implements:sel].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3276
    ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3277
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3278
"/"/    distances := selectors collect:[:each | each spellAgainst:selectorSoFar].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3279
"/"/    distances sortWith:selectors.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3280
"/"/    selectors reverse.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3281
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3282
    editAction :=
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3283
        [:selectedCompletionIndex |
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3284
            |chosen rest|
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3285
            
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3286
            chosen := selectors at:selectedCompletionIndex.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3287
            (editActionForArg notNil and:[ chosen includesSeparator ]) ifTrue:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3288
                editActionForArg value:chosen.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3289
            ] ifFalse:[    
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3290
                rest := chosen copyFrom:selectorSoFar size + 1.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3291
                codeView
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3292
                    undoableDo:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3293
                        codeView insertString:rest atLine:crsrLine col:crsrCol.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3294
                    ]
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3295
                    info:'Completion'.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3296
                codeView cursorToCharacterPosition:(crsrPos+1 + rest size - 1).
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3297
                codeView cursorRight. "/ kludge to make it visible
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3298
            ].
4618
e2085d943570 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  3299
        ].
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3300
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3301
    actionBlock
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3302
        value:selectors
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3303
        value:editAction
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  3304
        value:'selector'.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3305
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3306
    "Modified: / 04-07-2006 / 18:48:26 / fm"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3307
    "Created: / 10-11-2006 / 13:46:44 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3308
    "Modified: / 16-02-2010 / 10:13:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
5637
c37992ea83d4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5633
diff changeset
  3309
    "Modified: / 19-11-2017 / 14:47:34 / cg"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3310
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3311
5106
5303d78eb69a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5104
diff changeset
  3312
codeCompletionForTempVariable:node into:actionBlock
5303d78eb69a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5104
diff changeset
  3313
!
5303d78eb69a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5104
diff changeset
  3314
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3315
codeCompletionForVariable:node into:actionBlock
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3316
    |nonMetaClass crsrPos nm parent
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3317
     allVariables allDistances variablesAlreadyAdded nodeVal
5081
5478311e8ee5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5080
diff changeset
  3318
     char getDistanceComputeBlockWithWeight addWithFactorBlock allTheBest bestAssoc
5478311e8ee5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5080
diff changeset
  3319
     globalFactor localFactor selectorOfMessageToNode implementors argIdx namesUsed kwPart editActions suggestions nameIsOK longerNames setOfNames otherArgNames
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3320
     suggestionsWithInfo isLeftSideOfAssignment|
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3321
4302
f115f2ff999d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4301
diff changeset
  3322
    "/ Transcript show:'var in '; show:methodOrNil; show:' / '; showCR:classOrNil.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3323
    classOrNil notNil ifTrue:[
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3324
        nonMetaClass := classOrNil theNonMetaclass.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3325
    ].
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3326
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3327
    nm := node name.
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3328
    parent := node parent.
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3329
    isLeftSideOfAssignment := false.
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3330
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3331
    (parent notNil) ifTrue:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3332
        (parent isMessage) ifTrue:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3333
            node == parent receiver ifTrue:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3334
                selectorOfMessageToNode := parent selector
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3335
            ]
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3336
        ] ifFalse:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3337
            (parent isAssignment) ifTrue:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3338
                isLeftSideOfAssignment := (node == node parent variable).
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3339
            ].
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3340
        ].
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3341
    ].
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3342
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3343
    crsrPos := codeView characterPositionOfCursor.
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3344
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3345
    "/ 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
  3346
    "/ the user is probably looking for a message selector.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3347
    "/ If the variable represents a global, present its instance creation messages
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3348
    char := codeView characterBeforeCursor.
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3349
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3350
    (isLeftSideOfAssignment not and:[char == Character space]) ifTrue:[
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3351
        nm knownAsSymbol ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3352
            classOrNil isNil ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3353
                nodeVal := Smalltalk at:nm asSymbol.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3354
            ] ifFalse:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3355
                nodeVal := classOrNil topNameSpace at:nm asSymbol ifAbsent:[Smalltalk at:nm asSymbol].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3356
            ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3357
            nodeVal isBehavior ifTrue:[
4954
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3358
                |selectors selectors1 selectors2|
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3359
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3360
                selectors1 := OrderedSet new.
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3361
                selectors2 := OrderedSet new.
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3362
                nodeVal class
4954
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3363
                    withAllSuperclassesDo:[:cls |
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3364
                        cls methodDictionary keysAndValuesDo:[:sel :mthd |
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3365
                            |cat|
6022
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
  3366
                            cat := mthd category.
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
  3367
                            (cat notNil and:[cat sameAs: 'instance creation']) ifTrue:[
4954
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3368
                                selectors1 add:sel
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3369
                            ] ifFalse:[
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3370
                                "/ other category: look if it sends new, new: etc.
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3371
                                (mthd messagesSent includesAny:#(new new: basicNew basicNew:)) ifTrue:[
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3372
                                    selectors2 add:sel
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3373
                                ].
4954
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3374
                            ]
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3375
                        ]
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3376
                    ].
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3377
4954
5224a5211ae5 #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4951
diff changeset
  3378
                selectors := selectors1 order sort , #('-') , selectors2 order sort.
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3379
                editActions := selectors collect:[:word | self editActionToInsert:word].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3380
                actionBlock value:selectors value:editActions value:nil.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3381
"/                editAction :=
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3382
"/                    [:answer |
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3383
"/                        |s|
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3384
"/                        s := answer isInteger ifTrue:[selectors at:answer] ifFalse:[answer].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3385
"/                        codeView
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3386
"/                            undoableDo:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3387
"/                                codeView insertString:s atCharacterPosition:crsrPos.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3388
"/                                codeView cursorToCharacterPosition:crsrPos+s size.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3389
"/                            ]
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3390
"/                            info:'completion'.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3391
"/                    ].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3392
"/                actionBlock value:selectors value:editAction value:nil.
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3393
                ^ self.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3394
            ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3395
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3396
    ].
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3397
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3398
    "/ this is pure voodoo magic (tries to make a good spelling weight,
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3399
    "/ by weighting the number of startsWith characters into the spelling distance...)
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3400
    getDistanceComputeBlockWithWeight :=
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3401
        [:weight |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3402
            [:each |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3403
                |dist factor|
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3404
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3405
                dist := each spellAgainst:nm.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3406
                factor := 1.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3407
5027
e7feddec2933 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5007
diff changeset
  3408
                "/ bump the weight-factor if the name string is included
e7feddec2933 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5007
diff changeset
  3409
                (each includesString:nm) ifTrue:[
e7feddec2933 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5007
diff changeset
  3410
                    (each startsWith:nm) ifTrue:[
e7feddec2933 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5007
diff changeset
  3411
                        factor := 6 * weight * nm size.
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3412
                    ] ifFalse:[
5360
b258afc07129 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5324
diff changeset
  3413
                        (each endsWith:nm) ifTrue:[
b258afc07129 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5324
diff changeset
  3414
                            factor := 5 * weight * nm size.
b258afc07129 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5324
diff changeset
  3415
                        ] ifFalse:[
b258afc07129 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5324
diff changeset
  3416
                            nm size > 1 ifTrue:[
b258afc07129 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5324
diff changeset
  3417
                                factor := 4 * weight * nm size
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3418
                            ].
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3419
                        ].
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3420
                    ].
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3421
                ] ifFalse:[
5027
e7feddec2933 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5007
diff changeset
  3422
                    (each includesString:nm caseSensitive:false) ifTrue:[
e7feddec2933 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5007
diff changeset
  3423
                        (each asLowercase startsWith:nm asLowercase) ifTrue:[
e7feddec2933 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5007
diff changeset
  3424
                            factor := 4 * weight * nm size.
e7feddec2933 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5007
diff changeset
  3425
                        ] ifFalse:[
5360
b258afc07129 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5324
diff changeset
  3426
                            (each asLowercase endsWith:nm asLowercase) ifTrue:[
b258afc07129 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5324
diff changeset
  3427
                                factor := 3 * weight * nm size.
b258afc07129 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5324
diff changeset
  3428
                            ] ifFalse:[
b258afc07129 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5324
diff changeset
  3429
                                nm size > 1 ifTrue:[
b258afc07129 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5324
diff changeset
  3430
                                    factor := 2 * weight * nm size.
b258afc07129 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5324
diff changeset
  3431
                                ]
5027
e7feddec2933 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5007
diff changeset
  3432
                            ]
e7feddec2933 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5007
diff changeset
  3433
                        ]
e7feddec2933 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5007
diff changeset
  3434
                    ]
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3435
                ].
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3436
                dist := dist + (weight*factor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3437
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3438
                each -> (dist * weight)
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3439
             ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3440
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3441
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3442
    nameIsOK := false.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3443
    addWithFactorBlock :=
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3444
        [:eachNames :factor |
4689
2e20580b6878 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4665
diff changeset
  3445
            |distanceComputeBlock|
2e20580b6878 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4665
diff changeset
  3446
2e20580b6878 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4665
diff changeset
  3447
            distanceComputeBlock := (getDistanceComputeBlockWithWeight value:factor).
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3448
            eachNames do:[:nameToAdd |
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3449
                (nameToAdd = nm) ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3450
                    nameIsOK := true
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3451
                ] ifFalse:[ "/ not again
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3452
                    (variablesAlreadyAdded includes:nameToAdd) ifFalse:[  "/ not again
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3453
                        variablesAlreadyAdded add:nameToAdd.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3454
                        allVariables add:nameToAdd.
4689
2e20580b6878 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4665
diff changeset
  3455
                        allDistances add:(distanceComputeBlock value:nameToAdd).
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3456
                    ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3457
                ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3458
            ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3459
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3460
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3461
    nm isUppercaseFirst ifTrue:[
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3462
        globalFactor := 2.    "/ favour globals
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3463
        localFactor := 1.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3464
    ] ifFalse:[
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3465
        globalFactor := 1.    "/ favour locals
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3466
        localFactor := 2.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3467
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3468
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3469
    variablesAlreadyAdded := Set new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3470
    allVariables := OrderedCollection new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3471
    allDistances := OrderedCollection new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3472
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3473
    "/ are we in the method's selector spec ?
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3474
    (parent notNil
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3475
    and:[parent isMethod
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3476
    and:[parent arguments includes:node]]) ifTrue:[
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3477
        "/ yes -
4784
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3478
        "/ 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
  3479
        "/ of this method, and take that as a basis of the selection
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3480
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3481
        implementors := SystemBrowser
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3482
                            findImplementorsOf:(parent selector)
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3483
                            in:(Smalltalk allClasses)
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3484
                            ignoreCase:false.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3485
        "/ which argument is it
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3486
        argIdx := parent arguments indexOf:node.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3487
        implementors size > 50 ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3488
            implementors := implementors asOrderedCollection copyTo:50.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3489
        ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3490
        namesUsed := implementors
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3491
                        collect:[:eachImplementor |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3492
                            |parseTree|
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3493
                            parseTree := eachImplementor parseTree.
5539
04879fedd753 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5528
diff changeset
  3494
                            (parseTree notNil and:[parseTree arguments size >= argIdx])
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3495
                                ifFalse:nil
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3496
                                ifTrue:[ (parseTree arguments at:argIdx) name] ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3497
                        thenSelect:[:a | a notNil].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3498
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3499
        addWithFactorBlock value:namesUsed value:(2 * localFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3500
4784
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3501
        "/ try some commonly used arg names, such as aBoolean, anInteger, etc.
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3502
        nm size > 1 ifTrue:[
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3503
            |tryClassNamesWith|
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3504
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3505
            ((nm startsWith:'a') and:[(nm at:2) isUppercase]) ifTrue:[
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3506
                tryClassNamesWith := 'a'
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3507
            ] ifFalse:[
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3508
                (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
  3509
                    tryClassNamesWith := 'an'.
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3510
                ].
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3511
            ].
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3512
            tryClassNamesWith notNil ifTrue:[
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3513
                addWithFactorBlock
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3514
                    value:(Smalltalk keys
4784
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3515
                            collect:[:className | tryClassNamesWith,className]
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3516
                            thenSelect:[:name | name startsWith:nm])
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3517
                    value:(1.5 * localFactor)
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3518
            ].
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3519
        ].
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  3520
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3521
        classOrNil notNil ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3522
            "/ also, look for the keyword before the argument,
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3523
            "/ and see if there is such an instVar
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3524
            "/ if so, add it with -Arg
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3525
            parent selector isKeyword ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3526
                kwPart := parent selector keywords at:argIdx.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3527
                (classOrNil allInstVarNames includes:(kwPart copyButLast:1)) ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3528
                    addWithFactorBlock
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3529
                        value:(classOrNil allInstVarNames collect:[:nm| nm,'Arg'])
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3530
                        value:(1 * localFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3531
                ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3532
            ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3533
            "/ look for the variable names of any other method in that class
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3534
            otherArgNames := Set new.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3535
            classOrNil methodDictionary keysAndValuesDo:[:sel :mthd |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3536
                            |parseTree|
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3537
                            parseTree := mthd parseTree.
6013
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  3538
                            (parseTree notNil and:[parseTree arguments size ~~ 0])
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3539
                                ifFalse:nil
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3540
                                ifTrue:[ otherArgNames addAll:(parseTree arguments collect:[:each | each name])] ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3541
            addWithFactorBlock value:otherArgNames value:(1.5 * localFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3542
        ].
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3543
        addWithFactorBlock
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3544
            value:(codeView previousReplacements
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  3545
                                    collect:[:p | p value asString]
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3546
                                    thenSelect:[:s | s isValidSmalltalkIdentifier])
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  3547
            value:(1.3 * localFactor).
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3548
    ] ifFalse:[
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3549
        "/ locals in the block/method
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3550
        |names nameSpace|
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3551
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3552
        names := OrderedCollection withAll:node allVariablesOnScope.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3553
        setOfNames := Set withAll:names.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3554
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3555
        rememberedScopeNodes notNil ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3556
            "/ notNil when a parseError occurred.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3557
            rememberedScopeNodes do:[:eachScope |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3558
                (eachScope isMethod or:[eachScope isBlock]) ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3559
                    eachScope argumentNames do:[:eachName |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3560
                        (setOfNames includes:eachName) ifFalse:[ names add:eachName. setOfNames add:eachName ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3561
                    ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3562
                ] ifFalse:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3563
                    eachScope isSequence ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3564
                        eachScope temporaryNames do:[:eachName |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3565
                            (setOfNames includes:eachName) ifFalse:[ names add:eachName. setOfNames add:eachName ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3566
                        ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3567
                    ] ifFalse:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3568
                    ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3569
                ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3570
                "/ (setOfNames includesAll:(eachScope allDefinedVariables)) ifFalse:[ self halt].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3571
            ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3572
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3573
            rememberedScopeNodes do:[:eachScope |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3574
                eachScope variableNodesDo:[:var |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3575
                    (setOfNames includes:var name) ifFalse:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3576
                        names add:var name. setOfNames add:var name
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3577
                    ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3578
                ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3579
            ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3580
        ] ifFalse:[
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3581
            "/ tree must be there; in order to get as-yet-undeclared method locals
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3582
            "/ (further down the code), add them also
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3583
            tree variableNodesDo:[:var |
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3584
                |name|
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3585
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3586
                name := var name.
5552
2fe0fa28ecf5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5551
diff changeset
  3587
                (name isLowercaseFirst or:[isLeftSideOfAssignment not]) ifTrue:[
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3588
                    (setOfNames includes:name) ifFalse:[
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3589
                        names add:name.
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3590
                        setOfNames add:name
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3591
                    ]
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3592
                ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3593
            ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3594
        ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3595
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3596
        addWithFactorBlock value:names value:(4 * localFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3597
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3598
        classOrNil notNil ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3599
            "/ instance variables
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3600
            addWithFactorBlock value:classOrNil instVarNames value:(3 * localFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3601
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3602
            "/ inherited instance variables
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3603
            classOrNil superclass notNil ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3604
                addWithFactorBlock value:classOrNil superclass allInstVarNames value:(2.5 * localFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3605
            ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3606
        ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3607
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3608
        "/ magic:
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3609
        "/ if the node to be expanded is the receiver in a message, look for the selector sent to it
5771
efe639d65c0e #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5738
diff changeset
  3610
        "/ retrieve names which respond to those messages a higher weight
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3611
        selectorOfMessageToNode notNil ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3612
            |responders nonResponders|
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3613
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3614
            "/ responding to that message
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3615
            classOrNil notNil ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3616
                "/ private classes
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3617
                addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix])
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3618
                                   value:(2.75 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3619
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3620
                "/ class variables
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3621
                names := nonMetaClass classVarNames.
5771
efe639d65c0e #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5738
diff changeset
  3622
                responders := OrderedCollection new.
efe639d65c0e #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5738
diff changeset
  3623
                nonResponders := OrderedCollection new.
efe639d65c0e #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5738
diff changeset
  3624
                names do:[:classVar |
efe639d65c0e #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5738
diff changeset
  3625
                    |varValue|
efe639d65c0e #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5738
diff changeset
  3626
efe639d65c0e #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5738
diff changeset
  3627
                    varValue := nonMetaClass classVarAt:classVar.
efe639d65c0e #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5738
diff changeset
  3628
                    ((varValue isBridgeProxy not 
efe639d65c0e #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5738
diff changeset
  3629
                    and:[ varValue respondsTo:selectorOfMessageToNode])
efe639d65c0e #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5738
diff changeset
  3630
                        ifTrue:[responders]
efe639d65c0e #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5738
diff changeset
  3631
                        ifFalse:[nonResponders]) add:classVar
efe639d65c0e #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5738
diff changeset
  3632
                ].
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3633
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3634
                addWithFactorBlock value:responders value:(3.0 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3635
                addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3636
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3637
                "/ superclass var names
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3638
                nonMetaClass allSuperclassesDo:[:superClass |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3639
                    names := superClass classVarNames.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3640
                    responders := names select:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3641
                    nonResponders := names reject:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3642
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3643
                    addWithFactorBlock value:responders value:(2.75 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3644
                    addWithFactorBlock value:nonResponders value:(0.5 * 1 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3645
                ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3646
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3647
                isLeftSideOfAssignment ifFalse:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3648
                    "/ namespace vars
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3649
                    classOrNil topNameSpace ~~ Smalltalk ifTrue:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3650
                        names := classOrNil topNameSpace keys.
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3651
                        names := names reject:[:nm | nm includes:$:].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3652
                        names := names select:[:nm | nm isUppercaseFirst ].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3653
                        responders := names select:[:nsVar | |c| c := classOrNil topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3654
                        nonResponders := names reject:[:nsVar | |c| c := classOrNil topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3655
                        addWithFactorBlock value:responders value:(2.5 * globalFactor).
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3656
                        addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3657
                    ].
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3658
                ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3659
            ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3660
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3661
            isLeftSideOfAssignment ifFalse:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3662
                "/ globals
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3663
                names := Smalltalk keys.
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3664
                names := names reject:
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3665
                                [:nm |
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3666
                                    (nm includes:$:) and:[ (Smalltalk at:nm) isBehavior not]
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3667
                                ].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3668
                names := names reject:[:nm | nm startsWith:'Undeclared:::' ].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3669
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3670
                names := names select:[:nm | nm isUppercaseFirst ] as:OrderedCollection.
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3671
                responders := names select:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3672
                nonResponders := names reject:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3673
                addWithFactorBlock value:responders value:(1.5 * globalFactor).
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3674
                addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3675
            ].
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3676
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3677
            isLeftSideOfAssignment ifFalse:[ "/ no, we will not suggest assigning to pool vars
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3678
                classOrNil notNil ifTrue:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3679
                    "/ pool variables
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3680
                    classOrNil theNonMetaclass sharedPoolNames do:[:poolName |
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3681
                        |pool names|
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3682
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3683
                        pool := Smalltalk at:poolName.
5224
941b9aba81cc #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5203
diff changeset
  3684
                        pool notNil ifTrue:[
941b9aba81cc #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5203
diff changeset
  3685
                            names := pool classVarNames.
941b9aba81cc #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5203
diff changeset
  3686
                            names := names select:[:nm | nm isUppercaseFirst ].
941b9aba81cc #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5203
diff changeset
  3687
                            responders := names select:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
941b9aba81cc #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5203
diff changeset
  3688
                            nonResponders := names reject:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
941b9aba81cc #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5203
diff changeset
  3689
                            addWithFactorBlock value:responders value:(2.5 * globalFactor).
941b9aba81cc #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5203
diff changeset
  3690
                            addWithFactorBlock value:nonResponders value:(0.5 * 2.5 * globalFactor).
941b9aba81cc #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5203
diff changeset
  3691
                        ].
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3692
                    ].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3693
                ]
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3694
            ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3695
        ] ifFalse:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3696
            classOrNil notNil ifTrue:[
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3697
                isLeftSideOfAssignment ifFalse:[
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3698
                    "/ private classes
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3699
                    addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix])
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3700
                                       value:(2.75 * globalFactor).
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3701
                ].
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3702
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3703
                "/ class variables
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3704
                addWithFactorBlock value:nonMetaClass classVarNames value:(3.0 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3705
                nonMetaClass superclass notNil ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3706
                    addWithFactorBlock value:nonMetaClass superclass allClassVarNames value:(2.5 * globalFactor).
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3707
                ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3708
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3709
                isLeftSideOfAssignment ifFalse:[
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3710
                    "/ namespace vars
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3711
                    classOrNil topNameSpace ~~ Smalltalk ifTrue:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3712
                        names := classOrNil topNameSpace keys.
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3713
                        names := names reject:[:nm | nm includes:$:].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3714
                        names := names select:[:nm | nm isUppercaseFirst ].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3715
                        addWithFactorBlock value:names value:(2.5 * globalFactor).
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3716
                    ].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3717
                    "/ namespace vars
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3718
                    ((nameSpace := classOrNil nameSpace) notNil and:[nameSpace ~~ Smalltalk]) ifTrue:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3719
                        names := nameSpace isNameSpace ifTrue:[nameSpace keys] ifFalse:[nameSpace privateClasses collect:[:c | c nameWithoutPrefix]].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3720
                        names := names select:[:nm | nm isUppercaseFirst ].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3721
                        names := names reject:[:nm | nm includes:$:].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3722
                        addWithFactorBlock value:names value:(2.5 * globalFactor).
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3723
                    ].
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3724
                ].
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3725
                isLeftSideOfAssignment ifFalse:[ "/ no, we will not suggest assigning to pool vars
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3726
                    "/ pool variables
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3727
                    classOrNil theNonMetaclass sharedPoolNames do:[:poolName |
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3728
                        |pool names|
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3729
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3730
                        pool := Smalltalk at:poolName.
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3731
                        pool isNil ifTrue:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3732
                            Transcript showCR:'non existent pool: ',poolName
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3733
                        ] ifFalse:[
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3734
                            names := pool classVarNames.
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3735
                            addWithFactorBlock value:names value:(2.5 * globalFactor).
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3736
                        ]
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3737
                    ].
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3738
                ].
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3739
            ].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3740
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3741
            isLeftSideOfAssignment ifFalse:[
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3742
                "/ globals
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3743
                names := OrderedCollection new.
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3744
                Smalltalk keysDo:[:k |
5784
6d086db72816 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5771
diff changeset
  3745
                    |val|
6d086db72816 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5771
diff changeset
  3746
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3747
                    (k isUppercaseFirst
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3748
                    and:[ (k startsWith:'Undeclared:::') not
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3749
                    and:[ ((k includes:$:) and:[ (k includesString:'::') not]) not ]]) ifTrue:[
5784
6d086db72816 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5771
diff changeset
  3750
                        "/ ignore obsolete classes
6d086db72816 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5771
diff changeset
  3751
                        val := Smalltalk classNamed:k.
6d086db72816 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5771
diff changeset
  3752
                        (val isBehavior and:[val isObsolete]) ifFalse:[
6d086db72816 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5771
diff changeset
  3753
                            names add:k
6d086db72816 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5771
diff changeset
  3754
                        ]
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3755
                    ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3756
                ].
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3757
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3758
                "/ only consider all globals, if the first char of the completed name is uppercase;
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3759
                "/ otherwise, only consider names with a caseInsensitve prefix match
5552
2fe0fa28ecf5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5551
diff changeset
  3760
                nm isUppercaseFirst ifFalse:[
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3761
                    names := names select:[:globalName | globalName asLowercase startsWith: nm].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3762
                ].
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3763
                addWithFactorBlock value:names value:(1.5 * globalFactor).
4665
260b9fd17388 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4620
diff changeset
  3764
            ].
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3765
        ].
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3766
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3767
        isLeftSideOfAssignment ifFalse:[
5076
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3768
            "/ pseudos - assuming that thisContext is seldom used.
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3769
            "/ also assuming, that nil is short so its usually typed in.
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3770
            addWithFactorBlock value:#('self') value:(2.5 * localFactor).
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3771
            addWithFactorBlock value:#('nil') value:(0.5 * localFactor).
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3772
            addWithFactorBlock value:#('super' 'false' 'true') value:(2 * localFactor).
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3773
            addWithFactorBlock value:#('thisContext') value:(1 * localFactor).
9d8cf635a6cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5075
diff changeset
  3774
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3775
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3776
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3777
    allDistances isEmpty ifTrue:[^ self].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3778
4410
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  3779
"/ nope (foo := foo + 1) should be possible!!
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  3780
"/    (parent notNil and:[parent isAssignment]) ifTrue:[
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  3781
"/        "/ remove the left side of the assignment (to avoid foo := foo suggestions)
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  3782
"/        |i|
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  3783
"/
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  3784
"/        i := allDistances findFirst:[:entry | entry key = parent variable name].
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  3785
"/        i ~~ 0 ifTrue:[
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  3786
"/            allDistances removeAtIndex:i
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  3787
"/        ].
bee334ff01be class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4409
diff changeset
  3788
"/    ].
4385
d3381caeb327 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4382
diff changeset
  3789
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3790
    bestAssoc := allDistances at:1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3791
    bestAssoc := allDistances inject:bestAssoc into:[:el :best | el value > best value
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3792
                                                           ifTrue:[el]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3793
                                                           ifFalse:[best]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3794
                                                    ].
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3795
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  3796
    allDistances sort:[:a :b |
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3797
                                a value > b value ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3798
                                    true
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3799
                                ] ifFalse:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3800
                                    a value = b value ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3801
                                        a key < b key
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3802
                                    ] ifFalse:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3803
                                        false
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3804
                                    ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3805
                                ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3806
                      ].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3807
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3808
    allTheBest := allDistances.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3809
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3810
    nameIsOK ifTrue:[
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3811
        "/ if the name already exists, only allow longer names, if there are
5360
b258afc07129 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5324
diff changeset
  3812
        longerNames := allTheBest select:[:assoc | (assoc key startsWith:nm) or:[assoc key endsWith:nm]].
5033
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3813
        longerNames size < 30 ifTrue:[
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3814
            longerNames := allTheBest select:[:assoc | assoc key includesString:nm caseSensitive:false].
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3815
        ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3816
        longerNames isEmpty ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3817
            "/ no better name
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3818
            ^ self
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3819
        ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3820
        allTheBest := longerNames.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3821
    ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3822
5033
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3823
    allTheBest size > 20 ifTrue:[
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3824
        allTheBest := allTheBest copyTo:20.
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3825
"/        "/ remove all those which are below some threshold or are a prefix
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3826
"/        0.2 to:0.9 by:0.1 do:[:delta |
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3827
"/            |bestValue n|
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3828
"/
5033
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3829
"/            "/ if still too many, remove more and more
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3830
"/            allTheBest size > 50 ifTrue:[
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3831
"/                bestValue := bestAssoc value * delta.
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3832
"/                n := allTheBest select:[:entry | (entry key startsWith:nm) or:[ entry value >= bestValue ]].
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3833
"/                n size >= 15 ifTrue:[ allTheBest := n ].
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3834
"/            ]
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3835
"/        ].
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3836
"/        allTheBest size > 20 ifTrue:[
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3837
"/            "/ remove all those which are below some threshold
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3838
"/            0.2 to:0.9 by:0.1 do:[:delta |
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3839
"/                |bestValue n|
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3840
"/                "/ if still too many, remove more and more
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3841
"/                allTheBest size > 20 ifTrue:[
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3842
"/                    bestValue := bestAssoc value * delta.
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3843
"/                    allTheBest := allTheBest select:[:entry | entry value >= bestValue ].
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3844
"/                ]
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3845
"/            ].
743f882894d9 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5031
diff changeset
  3846
"/        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3847
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3848
    suggestions := allTheBest collect:[:assoc | assoc key].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3849
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3850
    "/ finally, the trick is to bring them into a reasonable order...
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3851
    "/ sort the prefix matchers by length, the others by spelling distance
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3852
    "/ and bring the prefix-matchers towards the beginning
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3853
    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
  3854
                   ,
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3855
                   (suggestions reject:[:s | s startsWith:nm]).
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  3856
4417
a523d812f6c1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  3857
    "/ if super is among them, add a full call to the completions
a523d812f6c1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  3858
    (suggestions includes:'super') ifTrue:[
4559
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3859
        (tree notNil
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3860
        and:[ tree isMethod ]) ifTrue:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3861
            Error handle:[:ex |
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3862
                Transcript showCR:'parse error in code completion ignored'.
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3863
            ] do:[
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3864
                suggestions addFirst:('super ',(Parser methodSpecificationForSelector:tree selector argNames:(tree argumentNames)),'.').
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3865
            ]
9a51a38177e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4548
diff changeset
  3866
        ].
4417
a523d812f6c1 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4416
diff changeset
  3867
    ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3868
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3869
    suggestionsWithInfo :=
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3870
        suggestions
4620
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3871
            collect:[:eachName |
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3872
                |val kind valAndKind printString|
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3873
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3874
                valAndKind := self valueAndKindOfVariable:eachName.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3875
                valAndKind isNil ifTrue:[
4620
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3876
                    eachName
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3877
                ] ifFalse:[
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3878
                    val := valAndKind first.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3879
                    kind := valAndKind second.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3880
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3881
                    val isBehavior ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3882
                        val isLoaded ifFalse:[
5090
c68614848447 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5089
diff changeset
  3883
                            eachName,' (= ', ('autoloaded class in ',(val category ? 'unknown category')) allItalic,' )'
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3884
                        ] ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3885
                            val isNameSpace ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3886
                                eachName,' ( ', 'namespace' allItalic,' )'
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3887
                            ] ifFalse:[
5090
c68614848447 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5089
diff changeset
  3888
                                eachName,' (= ', ('class in ',(val category ? 'unknown category')) allItalic,' )'
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3889
                            ]
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3890
                        ]
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3891
                    ] ifFalse:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3892
                        "/ Parser findBest:30 selectorsFor:'isLite' in:nil forCompletion:true
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3893
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3894
                        (val isLiteral and:[ (printString := val printString) size < 15 ]) ifTrue:[
5090
c68614848447 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5089
diff changeset
  3895
                            eachName,' (= ',printString allItalic,' )'
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3896
                        ] ifFalse:[
5370
ec87b8971f7b #BUGFIX by mawalch
mawalch
parents: 5368
diff changeset
  3897
                            eachName,' (= ',val class nameWithArticle allItalic,' )'
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3898
                        ].
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  3899
                    ].
4620
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3900
                ].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3901
            ].
3ee4c981e385 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4619
diff changeset
  3902
5081
5478311e8ee5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5080
diff changeset
  3903
    editActions := suggestions collect:[:word |
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3904
                     self editActionToReplaceNode:node by:word.
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3905
                   ].
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3906
    actionBlock value:suggestionsWithInfo value:editActions value:nil.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3907
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3908
    "Created: / 10-11-2006 / 13:16:33 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3909
    "Modified: / 16-02-2010 / 10:13:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  3910
    "Modified (comment): / 12-06-2017 / 12:34:46 / mawalch"
5552
2fe0fa28ecf5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5551
diff changeset
  3911
    "Modified: / 22-06-2017 / 06:56:42 / cg"
6022
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
  3912
    "Modified: / 03-03-2019 / 22:51:33 / Claus Gittinger"
5041
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3913
!
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3914
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3915
editActionToInsert:aString
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3916
    ^ [:index |
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3917
        codeView
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3918
            undoableDo:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3919
                codeView insertSelectedStringAtCursor:aString.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3920
                codeView dontReplaceSelectionOnInput
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3921
            ]
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3922
            info:'Completion'.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3923
    ].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3924
!
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3925
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3926
editActionToInsertFromSuggestions:suggestions
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3927
    ^ [:index |
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3928
        |answer|
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3929
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3930
        answer := suggestions at:index.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3931
        codeView
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3932
            undoableDo:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3933
                codeView insertSelectedStringAtCursor:answer.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3934
                codeView dontReplaceSelectionOnInput
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3935
            ]
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3936
            info:'Completion'.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3937
    ].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3938
!
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3939
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3940
editActionToReplaceCodeFrom:start to:stop by:aString
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3941
    ^ [:index |
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3942
        |oldVar oldLen newLen insertWithSpace|
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3943
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3944
        insertWithSpace := false.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3945
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3946
        start <= stop ifTrue:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3947
            oldVar := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3948
        ] ifFalse:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3949
            codeView characterBeforeCursor == Character space ifTrue:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3950
                insertWithSpace := true.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3951
            ].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3952
        ].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3953
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3954
        oldLen := stop - start + 1.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3955
        newLen := aString size.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3956
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3957
        codeView
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3958
            undoableDo:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3959
                insertWithSpace ifTrue:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3960
                    codeView insertSelectedStringAtCursor:aString
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3961
                ] ifFalse:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3962
                    codeView replaceFromCharacterPosition:start to:stop with:aString.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3963
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3964
                    (aString startsWith:oldVar) ifTrue:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3965
                        codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3966
                    ] ifFalse:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3967
                        codeView selectFromCharacterPosition:start to:start+newLen-1.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3968
                    ].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3969
                ].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3970
                codeView dontReplaceSelectionOnInput
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3971
            ]
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3972
            info:'Completion'.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3973
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3974
    ].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3975
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3976
    "Created: / 01-05-2016 / 18:47:40 / cg"
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3977
!
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  3978
5041
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3979
editActionToReplaceCodeFrom:start to:stop byWordIn:suggestions
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3980
    ^ [:index |
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3981
        |answer oldVar oldLen newLen insertWithSpace|
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3982
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3983
        insertWithSpace := false.
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3984
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3985
        answer := suggestions at:index.
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3986
        start <= stop ifTrue:[
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3987
            oldVar := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators.
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3988
        ] ifFalse:[
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3989
            codeView characterBeforeCursor == Character space ifTrue:[
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3990
                insertWithSpace := true.
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3991
            ].
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3992
        ].
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3993
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3994
        oldLen := stop - start + 1.
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3995
        newLen := answer size.
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3996
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3997
        codeView
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3998
            undoableDo:[
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  3999
                insertWithSpace ifTrue:[
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  4000
                    codeView insertSelectedStringAtCursor:answer
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  4001
                ] ifFalse:[
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  4002
                    codeView replaceFromCharacterPosition:start to:stop with:answer.
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  4003
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  4004
                    (answer startsWith:oldVar) ifTrue:[
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  4005
                        codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  4006
                    ] ifFalse:[
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  4007
                        codeView selectFromCharacterPosition:start to:start+newLen-1.
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  4008
                    ].
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  4009
                ].
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  4010
                codeView dontReplaceSelectionOnInput
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  4011
            ]
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  4012
            info:'Completion'.
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  4013
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  4014
    ].
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  4015
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  4016
    "Created: / 01-05-2016 / 18:47:40 / cg"
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  4017
!
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  4018
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4019
editActionToReplaceNode:node by:word
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4020
    ^ self editActionToReplaceCodeFrom:node start to:node stop by:word
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4021
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4022
    "Created: / 01-05-2016 / 18:44:09 / cg"
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4023
!
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4024
5041
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  4025
editActionToReplaceNode:node byWordIn:suggestions
5114
856f583b1fff #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5113
diff changeset
  4026
    ^ self editActionToReplaceCodeFrom:(node start) to:(node stop) byWordIn:suggestions
5041
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  4027
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  4028
    "Created: / 01-05-2016 / 18:44:09 / cg"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4029
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4030
5112
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4031
findBest:node for:selector inClasses:srchClassesArg
5606
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  4032
    "find the best suggestions for a partial selector in a given set of classes.
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  4033
     Notice: the returned collection is unsorted; it needs some postprocessing to
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  4034
     present the most reasonable items first"
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  4035
     
5112
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4036
    |srchClasses bestSelectors
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4037
     allMessagesSentToVariable classesImplementingAllMessages|
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4038
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4039
    srchClasses := srchClassesArg.
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4040
    Verbose == true ifTrue:[
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4041
        Transcript show:'node: '; showCR:node.
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4042
        Transcript show:'srchClasses: '; showCR:srchClasses.
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4043
    ].
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4044
    
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4045
    srchClasses isEmptyOrNil ifTrue:[
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4046
        node isVariable ifTrue:[
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4047
            allMessagesSentToVariable := Set new.
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4048
            rememberedNodes do:[:eachNode |
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4049
                eachNode allMessageNodesDo:[:eachMessage |
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4050
                    |msgReceiver msgSelector|
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4051
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4052
                    (msgReceiver := eachMessage receiver) isVariable ifTrue:[
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4053
                        msgReceiver name = node name ifTrue:[
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4054
                            (msgSelector := eachMessage selector) ~= selector ifTrue:[
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4055
                                allMessagesSentToVariable add:msgSelector
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4056
                            ]
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4057
                        ]
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4058
                    ]
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4059
                ]
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4060
            ].
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4061
            allMessagesSentToVariable notEmpty ifTrue:[
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4062
                "/ consider classes which implement all those messages.
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4063
                classesImplementingAllMessages := Smalltalk allImplementorsOf:(allMessagesSentToVariable first).
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4064
                allMessagesSentToVariable do:[:eachSelector |
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4065
                    classesImplementingAllMessages := classesImplementingAllMessages
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4066
                                                        select:[:cls | cls implements:eachSelector].
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4067
                ].
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4068
                srchClasses := classesImplementingAllMessages.
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4069
            ].
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4070
        ].
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4071
    ].
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4072
    bestSelectors := Set new.
5514
8f0a8c426831 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5512
diff changeset
  4073
    (srchClasses isEmptyOrNil or:[srchClasses size > 100]) ifTrue:[
5112
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4074
        bestSelectors addAll:( Parser findBest:50 selectorsFor:selector in:nil forCompletion:true ).
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4075
        Verbose == true ifTrue:[
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4076
            Transcript show:'bestSelectors (1): '; showCR:bestSelectors.
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4077
        ].
5514
8f0a8c426831 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5512
diff changeset
  4078
    ] ifFalse:[          
5112
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4079
        srchClasses do:[:srchClass |
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4080
            |bestForThisClass|
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4081
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4082
            bestForThisClass := Parser findBest:50 selectorsFor:selector in:srchClass forCompletion:true.
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4083
            bestForThisClass := self
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4084
                                withoutSelectorsUnlikelyFor:srchClass
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4085
                                from:bestForThisClass
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4086
                                forPartial:selector.
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4087
            Verbose == true ifTrue:[
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4088
                Transcript show:'bestSelectors (2): '; showCR:bestForThisClass.
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4089
            ].
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4090
            bestSelectors addAll:bestForThisClass.
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4091
        ].
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4092
    ].
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4093
    "/ remove the already typed-in selector itself, in case.
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4094
    bestSelectors remove:selector ifAbsent:[].
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4095
    bestSelectors := bestSelectors asOrderedCollection.
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4096
    ^ bestSelectors
5514
8f0a8c426831 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5512
diff changeset
  4097
8f0a8c426831 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 5512
diff changeset
  4098
    "Modified: / 13-03-2017 / 18:07:28 / cg"
5606
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  4099
    "Modified (comment): / 15-09-2017 / 11:00:01 / cg"
5112
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4100
!
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4101
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4102
findNodeForInterval:interval in:source
5272
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
  4103
    ^ self class findNodeForInterval:interval in:source
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4104
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4105
    "Modified: / 06-07-2011 / 12:42:53 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4106
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4107
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4108
findNodeForInterval:interval in:source allowErrors:allowErrors
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4109
    ^ self
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4110
	findNodeForInterval:interval in:source allowErrors:allowErrors
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4111
	mustBeMethod:false
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4112
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4113
    "Modified: / 16-09-2011 / 14:52:28 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4114
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4115
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4116
findNodeForInterval:interval in:source allowErrors:allowErrors mustBeMethod:mustBeMethod
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4117
    "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
  4118
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4119
    ^ self
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4120
	findNodeForInterval:interval in:source allowErrors:allowErrors
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4121
	mustBeMethod:mustBeMethod mustBeExpression:false
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4122
!
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4123
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4124
findNodeForInterval:interval in:source allowErrors:allowErrors mustBeMethod:mustBeMethod mustBeExpression:mustBeExpression
5070
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4125
    "parse source, and find the node which is in the given interval 
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4126
     (typically a selection or a word in the source).
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4127
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4128
     parse it as expression or method;
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4129
        if mustBeMethod is true, do not try as expression;
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4130
        if mustBeExpression is true, do not try as method
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4131
     expression syntax parsing is done in workspaces (doIt).
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4132
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4133
     Big hack as workaround a limitation of RBParser:
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4134
     in case of an error, the parent chain of a node is usually not yet set.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4135
     (because the code is written as: 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4136
        parentNode addChild:(self parseChild)
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4137
     and the parent-chain of the parsed child is set in addChild).
5070
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4138
     However:
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4139
        when doing code completion, having invalid syntax to parse is the normal case.
5070
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4140
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4141
     Workaround:
5070
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4142
        remember created nodes as the parse proceeds.
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4143
        Thus, I can construct a partial the parent chain.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4144
    "
4367
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  4145
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4146
    |intersectingNodes smallestIntersectingNode firstIntersectingNode
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4147
     lastIntersectingNode onErrorBlock
4373
93f9e6259b3a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4372
diff changeset
  4148
     nodeGenerationHook parserClass parser currentScopeNodes bestNode|
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4149
5900
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  4150
    partialString := nil.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4151
    interval isEmpty ifTrue: [^ nil].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4152
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  4153
    languageOrNil notNil ifTrue:[
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4154
        parserClass := languageOrNil parserClass.
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  4155
    ] ifFalse:[
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4156
        classOrNil notNil ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4157
            parserClass := classOrNil programmingLanguage parserClass.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4158
        ]
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  4159
    ].
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4160
    parserClass notNil ifTrue:[
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4161
        "/ hack
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4162
        parserClass == Parser ifTrue: [
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4163
            parserClass := RBParser.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4164
        ].
4373
93f9e6259b3a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4372
diff changeset
  4165
    ] ifFalse:[
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4166
        parserClass := RBParser.
4373
93f9e6259b3a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4372
diff changeset
  4167
    ].
93f9e6259b3a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4372
diff changeset
  4168
    parserClass isNil ifTrue: [^ nil].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4169
4361
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  4170
    rememberedScopeNodes := nil.
4434
b15ce7d47dd8 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4433
diff changeset
  4171
    rememberedNodes := OrderedCollection new.
4361
88d1ef0ad830 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4358
diff changeset
  4172
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4173
    "/ LastSource := nil.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4174
    source = LastSource ifTrue:[
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4175
        tree := LastParseTree.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4176
        tokens := LastScanTokens.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4177
    ] ifFalse:[
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4178
        intersectingNodes := OrderedCollection new.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4179
        currentScopeNodes := IdentitySet new.
5900
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  4180
        
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4181
        onErrorBlock :=
5900
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  4182
            [:str :err :nodesSoFarFromParser |
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  4183
                |nodes nodesSoFar partialStringStart partialStringEnd|
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  4184
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  4185
                nodesSoFar := nodesSoFarFromParser.
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  4186
                ((str includesString:'Unmatched') and:[str includesString:' in string literal']) ifTrue:[
5910
1f6e0165088c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  4187
                    parser isNil ifTrue:[
1f6e0165088c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  4188
                        "/ happesn during init of parser, when the first step is done before
1f6e0165088c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  4189
                        "/ parser is set (and returned) - sigh.
5911
3cb8e229215c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5910
diff changeset
  4190
                        ^ nil
5910
1f6e0165088c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  4191
                    ].   
5900
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  4192
                    partialStringStart := parser scanner tokenStart.
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  4193
                    partialStringEnd := parser scanner currentPosition.
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  4194
                    (source at:partialStringStart) == $' ifTrue:[partialStringStart := partialStringStart + 1].
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  4195
                    partialString := source copyFrom:partialStringStart to:partialStringEnd.
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  4196
                    partialStringInterval := partialStringStart to:partialStringEnd.
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  4197
                    "/ error is reported by scanner - no nodesSoFar passed in
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  4198
                    nodesSoFar := parser nodesSoFar.
5901
3784750b3bc5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5900
diff changeset
  4199
                    ^ nodesSoFar detectMax:[:node | node endPosition ? -1]
5900
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  4200
                ].    
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4201
                allowErrors ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4202
                    rememberedScopeNodes := currentScopeNodes.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4203
                    firstIntersectingNode notNil ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4204
                        ^ firstIntersectingNode
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4205
                    ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4206
                    nodesSoFar notNil ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4207
                        nodes := nodesSoFar asOrderedCollection
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4208
                                    collect:[:nd | nd whichNodeIntersects:interval]
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4209
                                    thenSelect:[:nd | nd notNil ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4210
                        nodes size == 1 ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4211
                            ^ nodes first
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4212
                        ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4213
                    ]
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4214
                ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4215
                nil
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4216
            ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4217
5658
22ffe8e819d6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5637
diff changeset
  4218
        self debuggingCodeFor:#DWIM is:[
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4219
            Transcript show:'looking for: '; showCR:interval.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4220
        ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4221
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4222
        nodeGenerationHook :=
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4223
            [:node |
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4224
                rememberedNodes add:node.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4225
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4226
                "/ 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
  4227
                "/ 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
  4228
                "/ what the semantic interpretation (especially: scope of variable) will be.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4229
                "/ therefore, we parse all, and return the found node at the end.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4230
                (node isMethod or:[node isBlock or:[node isSequence]]) ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4231
                    currentScopeNodes add:node.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4232
                ] ifFalse:[
5658
22ffe8e819d6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5637
diff changeset
  4233
                    self debuggingCodeFor:#DWIM is:[
22ffe8e819d6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5637
diff changeset
  4234
                        node isMessage ifTrue:[
22ffe8e819d6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5637
diff changeset
  4235
                            Transcript show:node; show:' '; show:node start; show:'->'; showCR:node stop.
22ffe8e819d6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5637
diff changeset
  4236
                        ].
22ffe8e819d6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5637
diff changeset
  4237
                    ].
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4238
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4239
                    (node intersectsInterval:interval) ifTrue:[
5658
22ffe8e819d6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5637
diff changeset
  4240
                        self debuggingCodeFor:#DWIM is:[
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4241
                            Transcript showCR:'yes'.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4242
                        ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4243
                        intersectingNodes add:node.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4244
                        firstIntersectingNode isNil ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4245
                            firstIntersectingNode := lastIntersectingNode := smallestIntersectingNode := node
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4246
                        ] ifFalse:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4247
                            |lenNode lenSmallest|
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4248
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4249
                            lenNode := (node stop - node start).
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4250
                            lenSmallest := (smallestIntersectingNode stop - smallestIntersectingNode start).
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4251
                            lenNode < lenSmallest ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4252
                                smallestIntersectingNode := node.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4253
                            ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4254
                            node start > lastIntersectingNode start ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4255
                                lastIntersectingNode := node.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4256
                            ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4257
                        ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4258
                    ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4259
                ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4260
            ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4261
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4262
        "/ one of the big problems when using the RBParser here is
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4263
        "/ that it behaves badly when a syntax error is encountered;
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4264
        "/ 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
  4265
        "/ completely parsed (for example, a blockNode gets the parent-method only
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4266
        "/ after parsing). Thus, when an error is encountered, we cannot walk
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4267
        "/ 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
  4268
        "/ an inner scope (allVariablesOnScope returns only a partial set).
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4269
        "/ 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
  4270
        "/ 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
  4271
        "/ parent gets set eventually, thus we might consider locals from sibling blocks.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4272
        "/ See rememberedScopeNodes handling above.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4273
        "/ Those other nodes are only remembered for failed parses;
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4274
        "/ if the parse is ok, rememberedScopeNodes will be nil.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4275
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4276
        mustBeExpression ifFalse:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4277
            tree := parserClass
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4278
                        parseMethod: source
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4279
                        setup:[:p |
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4280
                            parser := p.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4281
                            p rememberNodes:true.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4282
                            p rememberTokens:true.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4283
                            p nodeGenerationCallback:nodeGenerationHook
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4284
                        ]
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4285
                        onError: onErrorBlock.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4286
            parser notNil ifTrue:[ tokens := parser rememberedTokens ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4287
        ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4288
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4289
        mustBeMethod ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4290
            "/ only cache parsed methods
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4291
            tree notNil ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4292
                LastSource := source.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4293
                LastParseTree := tree.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4294
                LastScanTokens := tokens.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4295
            ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4296
        ] ifFalse:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4297
            (tree isNil or:[firstIntersectingNode isNil]) ifTrue:[
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4298
                "/ try as an expression
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4299
                tree := parserClass
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4300
                            parseExpression: source
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4301
                            setup:[:p |
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4302
                                parser := p.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4303
                                p rememberNodes:true.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4304
                                p rememberTokens:true.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4305
                                p nodeGenerationCallback:nodeGenerationHook
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4306
                            ]
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4307
                            onError: onErrorBlock.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4308
                parser notNil ifTrue:[ tokens := parser rememberedTokens ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4309
            ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4310
        ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4311
        lastIntersectingNode notNil ifTrue:[
5658
22ffe8e819d6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5637
diff changeset
  4312
            self debuggingCodeFor:#DWIM is:[
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4313
                Transcript show:'last: '; showCR:lastIntersectingNode.
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4314
            ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4315
            ^ lastIntersectingNode
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4316
        ].
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4317
        "/ firstIntersectingNode notNil ifTrue:[ ^ firstIntersectingNode ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4318
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4319
4367
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  4320
    bestNode := self findNodeForInterval:interval inParseTree:tree.
5658
22ffe8e819d6 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5637
diff changeset
  4321
    self debuggingCodeFor:#DWIM is:[
4934
9b2c18bd9e9c #UI_ENHANCEMENT
Claus Gittinger <cg@exept.de>
parents: 4933
diff changeset
  4322
        Transcript show:'best: '; showCR:bestNode.
4367
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  4323
    ].
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  4324
    ^ bestNode
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4325
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4326
    "Created: / 16-09-2011 / 14:52:08 / cg"
4407
59eecb68b4fb class: DoWhatIMeanSupport
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4392
diff changeset
  4327
    "Modified: / 18-09-2013 / 16:47:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4328
    "Modified (comment): / 01-05-2016 / 10:05:10 / cg"
5911
3cb8e229215c #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5910
diff changeset
  4329
    "Modified: / 22-09-2018 / 09:40:57 / Claus Gittinger"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4330
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4331
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4332
findNodeForInterval:interval inParseTree:parseTree
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4333
    |node|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4334
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4335
    interval isEmpty ifTrue: [^ nil].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4336
    parseTree isNil ifTrue:[^ nil].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4337
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4338
    node := parseTree whichNodeIsContainedBy:interval.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4339
    node isNil ifTrue:[
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4340
	node := parseTree whichNodeIntersects:interval.
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4341
	node isNil ifTrue: [
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4342
	    node := self findNodeIn:parseTree forInterval:interval
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4343
	].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4344
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4345
    ^ node
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4346
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4347
    "Modified: / 10-11-2006 / 13:13:58 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4348
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4349
5272
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
  4350
findNodeIn:aTree forInterval:anInterval
537ecde55d3d #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5253
diff changeset
  4351
    ^ self class findNodeIn:aTree forInterval:anInterval
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4352
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4353
    "Modified: / 20-11-2006 / 12:31:12 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4354
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4355
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4356
insertAdditonalStuffAfterSelector:chosenCompletion
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4357
    |optionalExtraSpace|
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4358
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4359
    optionalExtraSpace := (codeView characterAfterCursor isSeparator)
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4360
                            ifTrue:['']
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4361
                            ifFalse:[' '].
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4362
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4363
    (
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4364
        #(
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4365
            'ifTrue:' 'ifFalse:' 'ifTrue:ifFalse:' 'ifFalse:ifTrue:'
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4366
            'and:' 'or:' 'timesRepeat:' 'whileTrue:' 'whileFalse:'
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4367
        ) includes:chosenCompletion
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4368
    ) ifTrue:[
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4369
        codeView insertStringAtCursor:('[',optionalExtraSpace,']').
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4370
        "/ codeView cursorLeft:1+extra size.
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4371
    ].
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4372
    (
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4373
        #(
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4374
            'collect:' 'select:' 'reject:' 'do:'
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4375
        ) includes:chosenCompletion
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4376
    ) ifTrue:[
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4377
        codeView insertStringAtCursor:('[:each | ]',optionalExtraSpace).
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4378
        codeView cursorLeft:1+optionalExtraSpace size.
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4379
    ].
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4380
    (
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4381
        #(
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4382
            'contains:' 'findFirst:' 'detect:'
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4383
        ) includes:chosenCompletion
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4384
    ) ifTrue:[
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4385
        codeView insertStringAtCursor:('[:some | ]',optionalExtraSpace).
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4386
        codeView cursorLeft:1+optionalExtraSpace size.
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4387
    ].
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4388
    (
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4389
        #(
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4390
            'remove:ifAbsent:' 'detect:ifNone:'
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4391
        ) includes:chosenCompletion
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4392
    ) ifTrue:[
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4393
        codeView insertStringAtCursor:('[]',optionalExtraSpace).
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4394
        codeView cursorLeft:1+optionalExtraSpace size.
4421
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4395
    ].
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4396
!
adbde1681089 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
  4397
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4398
messagesSentTo:varName in:aTree
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4399
    |messagesToReceiver collector|
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4400
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4401
    collector :=
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4402
        [:node | 
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4403
            (node isMessage 
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4404
            and:[node receiver isVariable
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4405
            and:[node receiver name = varName]]) ifTrue:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4406
                messagesToReceiver add:(node selector)
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4407
            ].
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4408
        ].
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4409
        
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4410
    "/ collect messages sent
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4411
    messagesToReceiver := Set new.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4412
    "/ remembered nodes is nonNil if parser aborted with error
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4413
    rememberedNodes notNil ifTrue:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4414
        rememberedNodes do:collector.
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4415
    ] ifFalse:[
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4416
        tree allMessageNodesDo:collector.
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4417
    ]. 
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4418
    ^ messagesToReceiver
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4419
!
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4420
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4421
old_askUserForCompletion:what for:codeView from:allTheBest
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4422
    |list resources choice lastChoice|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4423
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4424
    allTheBest isEmpty ifTrue:[ ^ nil ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4425
    allTheBest size == 1 ifTrue:[ ^ allTheBest first ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4426
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4427
    list := allTheBest.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4428
    LastChoices notNil ifTrue:[
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4429
	lastChoice := LastChoices at:what ifAbsent:nil.
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4430
	lastChoice notNil ifTrue:[
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4431
	    "/ move tha last choice to the top of the list, if it is in.
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4432
	    (list includes: lastChoice) ifTrue:[
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4433
		(list indexOf: lastChoice) < 10 ifTrue:[
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4434
		    list := {lastChoice allBold } , (list copyWithout:lastChoice).
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4435
		]
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4436
	    ]
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4437
	].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4438
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4439
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4440
    list size < 30 ifTrue:[
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4441
	|menu idx exitKey|
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4442
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4443
	menu := PopUpMenu labels:list.
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4444
	menu hideOnKeyFilter:[:key | |hide|
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4445
		hide := ( #( CursorDown CursorUp Escape Return ) includes: key) not.
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4446
		hide ifTrue:[
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4447
		    exitKey := key.
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4448
		].
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4449
		hide].
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4450
	menu memorizeLastSelection:3 "sigh, not 1 because of heading!!".
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4451
	idx := menu startUpWithHeading:'Choose ',what.
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4452
	idx == 0 ifTrue:[
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4453
	    exitKey notNil ifTrue:[
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4454
		codeView keyPress:exitKey x:0 y:0.
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4455
	    ].
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4456
	    ^ nil
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4457
	].
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4458
	choice := list at:idx.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4459
    ] ifFalse:[
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4460
	resources := codeView application isNil
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4461
			ifTrue:[ codeView resources]
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4462
			ifFalse:[ codeView application resources ].
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4463
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4464
	choice := Dialog
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4465
	   choose:(resources string:'Choose ',what)
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4466
	   fromList:list
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4467
	   lines:20
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4468
	   initialSelection:(list firstIfEmpty:nil)
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4469
	   title:(resources string:'Code completion').
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4470
	choice isNil ifTrue:[^ nil].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4471
    ].
4301
90f7571df306 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4284
diff changeset
  4472
    choice := choice string.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4473
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4474
    LastChoices isNil ifTrue:[
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4475
	LastChoices := Dictionary new.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4476
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4477
    LastChoices at:what put:choice.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4478
    ^ choice
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4479
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4480
    "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
  4481
    "Modified: / 28-08-2013 / 15:28:01 / cg"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4482
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4483
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4484
sortSelectors:list forSelector:selector lcSelector:lcSelector
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4485
    list sort: [:a :b |
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4486
        |aBeforeB|
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4487
5613
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  4488
"/        (a startsWith:'sho') ifTrue:[
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  4489
"/            (b startsWith:'sho') ifTrue:[
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  4490
"/                self halt.
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  4491
"/            ].
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  4492
"/        ].
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  4493
        
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4494
        (a startsWith:selector) ifTrue:[
5613
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  4495
            (b startsWith:selector) ifTrue:[
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  4496
                aBeforeB := (a size < b size) or:[a < b]
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  4497
            ] ifFalse:[
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4498
                aBeforeB := true
5613
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  4499
            ] 
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4500
        ] ifFalse:[    
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4501
            (b startsWith:selector) ifTrue:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4502
                aBeforeB := false
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4503
            ]
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4504
        ].
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4505
        aBeforeB isNil ifTrue:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4506
            aBeforeB := a asLowercase < b asLowercase.
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4507
            (a asLowercase startsWith:lcSelector) ifTrue:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4508
                (b asLowercase startsWith:lcSelector) ifFalse:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4509
                    aBeforeB := true
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4510
                ]
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4511
            ] ifFalse:[    
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4512
                (b asLowercase startsWith:lcSelector) ifTrue:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4513
                    aBeforeB := false
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4514
                ]
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4515
            ].
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4516
        ].
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4517
        aBeforeB
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4518
    ].
5613
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  4519
46c0f7f9b92c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5612
diff changeset
  4520
    "Modified: / 30-09-2017 / 14:10:06 / cg"
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4521
!
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4522
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4523
sortUsefulSelectorsIn:selectorList
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4524
    "/ cosmetics: 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4525
    "/  ifTrue / whileTrue should come before ifFalse/whileFalse
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4526
    #(
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4527
        ifTrue:         ifFalse:
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4528
        ifTrue:ifFalse: ifFalse:ifTrue:
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4529
        whileTrue:      whileFalse:
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4530
        whileTrue       whileFalse
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4531
        whileTrue:      whileTrue
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4532
        whileFalse:     whileFalse
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4533
        new:            basicNew:
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4534
        new             basicNew
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4535
    ) pairWiseDo:[:sel1 :sel2 |
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4536
        |idx1 idx2|
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4537
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4538
        (idx1 := selectorList indexOf:sel1) ~~ 0 ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4539
            (idx2 := selectorList indexOf:sel2) ~~ 0 ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4540
                idx1 > idx2 ifTrue:[ 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4541
                    selectorList swap:idx1 with:idx2
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4542
                ] 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4543
            ] 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4544
        ].
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4545
    ].
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4546
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4547
    "Created: / 01-05-2016 / 17:48:02 / cg"
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4548
!
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4549
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4550
splitSelectorList:list by:condition
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4551
    |part1 part2 newList|
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4552
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4553
    part1 := list select:condition.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4554
    part2 := list reject:condition.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4555
    part1 isEmpty ifTrue:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4556
        newList := part2.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4557
    ] ifFalse:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4558
        part2 isEmpty ifTrue:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4559
            newList := part1.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4560
        ] ifFalse:[
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4561
            newList := part1 , part2.
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4562
        ]
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4563
    ].
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4564
    ^ newList
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4565
!
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  4566
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4567
treeForCode:source allowErrors:allowErrors
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4568
    |tree|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4569
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4570
    source = LastSource ifTrue:[
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4571
	tree := LastParseTree.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4572
    ] ifFalse:[
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4573
	tree := RBParser
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4574
		parseMethod:source
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4575
		onError: [:str :err :nodesSoFar :parserOrNil|
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4576
			allowErrors ifTrue:[
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4577
			    "/ parserOrNil isNil if raised by the scanner
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4578
			    parserOrNil notNil ifTrue:[
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4579
				^ parserOrNil currentMethodNode
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4580
			    ]
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4581
			].
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4582
			^ nil
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4583
		    ]
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4584
		proceedAfterError:false
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4585
		rememberNodes:true.
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4586
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4587
	tree notNil ifTrue:[
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4588
	    LastSource := source.
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4589
	    LastParseTree := tree.
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  4590
	]
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4591
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4592
    ^ tree
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
    "Modified: / 13-01-2012 / 11:54:30 / cg"
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4595
!
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4596
4524
54079876ac80 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4488
diff changeset
  4597
tryCodeCompletionWithSource:source nodeInterval:interval at:characterPositionOfCursor mustBeExpression:mustBeExpression into:actionBlock
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  4598
    "this is tried multiple times;
4931
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4599
        first with cursor line only
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4600
        then with the source copied up to the cursor position,
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4601
        then with the full source.
4381
43de05e6af6c class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
  4602
     Either one may give better results (for example, when completing
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4603
     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
  4604
     legal, but stupid message send to be parsed...
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4605
     (which happens often after inserting)"
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4606
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4607
    |node nodeParent checkedNode characterBeforeCursor|
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4608
5505
485ae56088f2 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5504
diff changeset
  4609
    characterPositionOfCursor < 1 ifTrue:[^ self].
485ae56088f2 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5504
diff changeset
  4610
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4611
    "/ this is too naive and stupid; if there is a syntactic error,
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4612
    "/ 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
  4613
    "/ 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
  4614
    "/ without any progress.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4615
    "/ 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
  4616
    "/ as it parses the code. Stop, when the interval is hit.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4617
    "/ that will also work for syntactic incorrect source code.
4524
54079876ac80 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4488
diff changeset
  4618
    (mustBeExpression not and:[methodOrNil notNil or:[classOrNil notNil]]) ifTrue:[
4931
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4619
        node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:true.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4620
    ].           
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4621
    node isNil ifTrue:[
4931
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4622
        node := self findNodeForInterval:interval in:source allowErrors:true mustBeMethod:false mustBeExpression:true.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4623
        node isNil ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4624
            "/ Transcript showCR:'No parseNode found (syntax error before or in comment?)'.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4625
            self information:'No parseNode found (syntax error before or in comment?)'.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4626
            ^ self.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4627
        ].
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4628
    ].
5900
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  4629
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  4630
    "/ if we are in a partial string,
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  4631
    "/ try the special string-expansion hook (hook for expecco)
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  4632
    partialString notNil ifTrue:[
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  4633
        self codeCompletionForLiteralString:partialString node:node in:source considerAll:false into:actionBlock.
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  4634
        ^ self.
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  4635
    ].
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  4636
    
5106
5303d78eb69a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5104
diff changeset
  4637
    "/ (source startsWith:'sel') ifTrue:[self halt].
4544
a07061d382ce class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4543
diff changeset
  4638
    nodeParent := node parent.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4639
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4640
    (node isVariable
4544
a07061d382ce class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4543
diff changeset
  4641
    and:[ nodeParent notNil
a07061d382ce class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4543
diff changeset
  4642
    and:[ nodeParent isMessage
4368
442517f0d19d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
  4643
    and:[ node stop < (characterPositionOfCursor-1) ]]]) ifTrue:[
4931
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4644
        node := nodeParent.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4645
        nodeParent := node parent.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4646
    ].
5508
6215fe395e12 #BUGFIX by mawalch
mawalch
parents: 5505
diff changeset
  4647
    (characterPositionOfCursor-1 max:1) > source size ifTrue:[^ self].
4525
71ebd312132a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4524
diff changeset
  4648
    characterBeforeCursor := source at:(characterPositionOfCursor-1 max:1). "/ codeView characterBeforeCursor.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4649
    characterBeforeCursor isNil ifTrue:[ "at begin of line" ^ self].
4358
d9978bce6853 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4356
diff changeset
  4650
    characterBeforeCursor == $. ifTrue:[ "at end of statement" ^ self].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4651
 
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4652
    node isVariable ifTrue:[
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4653
        |nodeIsInTemporaries nodeIsInBlockArguments nodeIsInMethodArguments |
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4654
4931
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4655
        nodeIsInTemporaries :=
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4656
            nodeParent notNil
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4657
            and:[ nodeParent isSequence
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4658
            and:[ nodeParent temporaries notEmptyOrNil
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4659
            and:[ node stop <= nodeParent temporaries last stop ]]]. 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4660
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4661
        nodeIsInBlockArguments :=
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4662
            node blockScope notNil
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4663
            and:[ node blockScope arguments notEmptyOrNil
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4664
            and:[ node stop <= node blockScope arguments last stop ]].
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4665
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4666
        (nodeIsInBlockArguments not and:[rememberedScopeNodes notNil]) ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4667
            "/ sigh - parent (and therefore blockScope) is unknown if parser has error
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4668
            nodeIsInBlockArguments := 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4669
                rememberedScopeNodes 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4670
                    contains:[:scope |
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4671
                        (scope isMethod or:[scope isBlock])
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4672
                        and:[scope arguments notEmpty
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4673
                        and:[scope arguments first start <= node start
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4674
                        and:[scope arguments last stop >= node stop]]].
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4675
                    ].        
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4676
        ].
5106
5303d78eb69a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5104
diff changeset
  4677
        nodeIsInTemporaries ifTrue:[ self codeCompletionForTempVariable:node into:actionBlock. ^ self ]. 
5303d78eb69a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5104
diff changeset
  4678
        nodeIsInBlockArguments ifTrue:[ self codeCompletionForBlockArgument:node into:actionBlock. ^ self ]. 
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4679
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4680
        "/ for variable completion, cursor must be right after the node 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4681
        codeView characterPositionOfCursor = (node stop + 1) ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4682
            codeView characterBeforeCursor ~= Character space ifTrue:[
4931
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4683
                self codeCompletionForVariable:node into:actionBlock.
5035
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4684
                ^ self.
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4685
            ]. 
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4686
        ].
5523
cf21c956598b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5514
diff changeset
  4687
        "/ if right after a global, which is a class, look for implemented instance creation methods; offer them
cf21c956598b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5514
diff changeset
  4688
        node isGlobal ifTrue:[
cf21c956598b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5514
diff changeset
  4689
            |class instCreators selectors|
cf21c956598b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5514
diff changeset
  4690
            
cf21c956598b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5514
diff changeset
  4691
            (class := Smalltalk classNamed:node name) notNil ifTrue:[
cf21c956598b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5514
diff changeset
  4692
                (instCreators := class theMetaclass methodsInCategory:'instance creation') notEmpty ifTrue:[
cf21c956598b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5514
diff changeset
  4693
                    selectors := instCreators collect:[:m | m selector].
cf21c956598b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5514
diff changeset
  4694
                    actionBlock 
cf21c956598b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5514
diff changeset
  4695
                        value:selectors 
cf21c956598b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5514
diff changeset
  4696
                        value:(selectors collect:[:sel | self editActionToInsert:sel])
cf21c956598b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5514
diff changeset
  4697
                        value:'instance creation'.
cf21c956598b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5514
diff changeset
  4698
                ].
cf21c956598b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5514
diff changeset
  4699
            ].    
cf21c956598b #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5514
diff changeset
  4700
        ]
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4701
    ].
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4702
5035
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4703
false ifTrue:[
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4704
        codeView characterPositionOfCursor = (node stop + 2) ifTrue:[
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4705
            |classes cls| 
5035
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4706
            "/ after a variable;
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4707
            "/ offer local messages, if receiver type is known
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4708
            classes := (self classesOfNode:node).
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4709
            classes notEmptyOrNil ifTrue:[
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4710
                classes size > 1 ifTrue:[
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4711
                    cls := classes anElement.
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4712
                ] ifFalse:[    
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4713
                    cls := Behavior commonSuperclassOf:classes.
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4714
                ]
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4715
            ]. 
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4716
            cls notNil ifTrue:[
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4717
                |clsSelectors moreSelectors|
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4718
            
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4719
                "/ completion in a message-send
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4720
                clsSelectors := cls methodDictionary keys. "/ Parser findBest:50 selectorsFor:'' in:cls forCompletion:true.
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4721
                clsSelectors size < 30 ifTrue:[
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4722
                    cls superclass notNil ifTrue:[
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4723
                        moreSelectors := cls superclass methodDictionary keys.
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4724
                        clsSelectors size + moreSelectors size < 30 ifTrue:[
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4725
                            clsSelectors := clsSelectors , moreSelectors.
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4726
                        ].
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4727
                    ].    
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4728
                ].
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4729
                "/ self codeCompletionForMessage:checkedNode into:actionBlock.
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4730
                actionBlock value:clsSelectors value:nil value:nil.
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4731
                ^ self.
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4732
            ]
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4733
        ]
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  4734
].
4367
dd00d1570f88 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4366
diff changeset
  4735
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4736
    node isLiteral ifTrue:[
4931
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4737
        "/ however, user may want to complete a symbol inside a literal array!!
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4738
        node value isArray ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4739
            node token isLiteralArray ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4740
                |elementBeforeCursor searcher|
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4741
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4742
                elementBeforeCursor := node token value detect:[:anElementToken | characterPositionOfCursor == (anElementToken stop + 1)] ifNone:nil.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4743
                elementBeforeCursor isNil ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4744
                    searcher :=
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4745
                        [:tok :check |
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4746
                            tok isLiteralArray ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4747
                                tok value inject:nil into:[:found :el | found ifNil:[searcher value:el value:check]]
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4748
                            ] ifFalse:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4749
                                (check value:tok) ifTrue:[tok] ifFalse:[nil]
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4750
                            ]
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4751
                        ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4752
                    elementBeforeCursor := searcher value:node token value:[:anElementToken | characterPositionOfCursor == (anElementToken stop)].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4753
                ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4754
                (elementBeforeCursor notNil and:[ elementBeforeCursor value isSymbol ]) ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4755
                    self codeCompletionForLiteralSymbol:nil element:elementBeforeCursor considerAll:true into:actionBlock.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4756
                    ^ self.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4757
                ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4758
            ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4759
        ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4760
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4761
        "/ cursor must be right after the literal
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4762
        characterPositionOfCursor == (node stop + 1) ifFalse:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4763
            ^ self
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4764
        ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4765
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4766
        node value isSymbol ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4767
            self codeCompletionForLiteralSymbol:node element:nil considerAll:false into:actionBlock.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4768
            ^ self.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4769
        ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4770
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4771
        "/ huh - completing strings, numbers or what?
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4772
        (nodeParent notNil
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4773
            and:[ nodeParent isMessage
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4774
            and:[ nodeParent isKeyword ]])
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4775
        ifFalse:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4776
            ^ self
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4777
        ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4778
        "/ no, move up and try completing the outer keyword message (next arg)
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4779
        node := nodeParent.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4780
        nodeParent := node parent.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4781
    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4782
5050
ffb39e4501e5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5049
diff changeset
  4783
    Verbose == true ifTrue:[
ffb39e4501e5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5049
diff changeset
  4784
        Transcript show:'node is '.
ffb39e4501e5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5049
diff changeset
  4785
        Error ignoreIn:[ Transcript show:node ].
ffb39e4501e5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5049
diff changeset
  4786
        Transcript cr.
ffb39e4501e5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5049
diff changeset
  4787
    ].
ffb39e4501e5 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5049
diff changeset
  4788
    
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4789
    "/ if in a keyword-argument position...
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4790
    node isMessage ifTrue:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4791
        "/ where are we?
5379
0f89327edf3c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5370
diff changeset
  4792
        node selectorString last == $: "node selector isSymbol" ifTrue:[
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4793
            characterBeforeCursor == $: ifTrue:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4794
                |argIdx senders implementors receiverClasses selectorUpToCursor implementorOfSelectorUpToCursor|
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4795
                "/ about to enter an argument?
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4796
                argIdx := node selectorParts keysAndValuesDetectKey:[:idx :part |
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4797
                            part stop == (codeView characterPositionOfCursor-1). 
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4798
                          ] ifNone:nil.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4799
                argIdx notNil ifTrue:[          
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4800
                    selectorUpToCursor := ((node selectorParts collect:#value) copyTo:argIdx) asStringWith:''.        
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4801
                    implementors := Set new.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4802
                    "/ find senders of this message, and see if they call it with a block argument
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4803
                    "/ this takes too long for a completion;
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4804
                    "/    Smalltalk allClassesDo:[:cls |
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4805
                    "/        cls instAndClassMethodsDo:[:m |
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4806
                    "/            (m sendsMessageForWhich:[:sel | sel startsWith:node selector]) ifTrue:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4807
                    "/                senders add:m
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4808
                    "/            ].    
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4809
                    "/        ]
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4810
                    "/    ].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4811
                    "/ therefore, restrict to a max. of 5 classes
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4812
                    receiverClasses := self classesOfNode:node receiver.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4813
                    (receiverClasses notEmptyOrNil and:[receiverClasses size <= 5]) ifTrue:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4814
                        receiverClasses do:[:eachPossibleReceiverClass |
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4815
                            eachPossibleReceiverClass withAllSuperclassesDo:[:cls |
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4816
                                cls methodDictionary keysAndValuesDo:[:sel :mthd |
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4817
                                    (sel startsWith:selectorUpToCursor) ifTrue:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4818
                                        implementors add:mthd.
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4819
                                        (sel = selectorUpToCursor) ifTrue:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4820
                                            implementorOfSelectorUpToCursor := implementorOfSelectorUpToCursor ? mthd
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4821
                                        ].    
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4822
                                    ].    
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4823
                                ].    
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4824
                            ]
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4825
                        ]
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4826
                    ].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4827
                    implementorOfSelectorUpToCursor notNil ifTrue:[
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4828
                        |tree argName|
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4829
                        
5123
92455fb1f46f #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5119
diff changeset
  4830
                        SourceCodeManagerError handle:[:ex |
92455fb1f46f #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5119
diff changeset
  4831
                        ] do:[    
5392
2dc73ed82d4b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 5385
diff changeset
  4832
                            tree := implementorOfSelectorUpToCursor parseTree. 
5462
6a7b577cd2b9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5453
diff changeset
  4833
                            (tree notNil and:[tree argumentNames size >= argIdx]) ifTrue:[
5392
2dc73ed82d4b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 5385
diff changeset
  4834
                                argName := tree argumentNames at:argIdx.
2dc73ed82d4b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 5385
diff changeset
  4835
                                (argName includesString:'block' caseSensitive:false) ifTrue:[
2dc73ed82d4b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 5385
diff changeset
  4836
                                    actionBlock value:{'[ "',argName,'" ]'}
2dc73ed82d4b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 5385
diff changeset
  4837
                                                value:{ self editActionToInsert:('[ "',argName,'" ]') }
2dc73ed82d4b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 5385
diff changeset
  4838
                                                value:'block argument'
2dc73ed82d4b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 5385
diff changeset
  4839
                                ]. 
5123
92455fb1f46f #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5119
diff changeset
  4840
                            ].
92455fb1f46f #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5119
diff changeset
  4841
                        ].    
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4842
                    ] ifFalse:[    
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4843
                        implementors notEmpty ifTrue:[
5082
87e1ffeceb8a #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5081
diff changeset
  4844
                            self breakPoint:#cg.
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4845
                        ].    
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4846
                    ].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4847
                ].    
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4848
            ].    
5528
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  4849
        ].
5080
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4850
    ].
0842b08b7040 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5076
diff changeset
  4851
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4852
    (node isVariable or:[node isBlock and:[node stop notNil]]) ifTrue:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4853
        (characterPositionOfCursor == (node stop + 1)
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4854
        "/ hack (spaces at end of line)
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4855
        or:[characterPositionOfCursor == (node stop)]) ifTrue:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4856
            codeView characterBeforeCursor == Character space ifTrue:[
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4857
                self codeCompletionForMessageTo:node into:actionBlock.
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4858
                ^ self
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4859
            ].
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4860
        ].
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4861
    ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4862
5114
856f583b1fff #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5113
diff changeset
  4863
    "/ characterBeforeCursor == $) ifTrue:[self halt].
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  4864
4933
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  4865
    "/ move outward, until we find a message-send node,
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  4866
    "/ or the method's selector pattern node.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4867
    checkedNode := node.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4868
    [checkedNode notNil] whileTrue:[
5322
407a341d0c83 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5312
diff changeset
  4869
        (characterPositionOfCursor <= ((checkedNode stop ? source size)+1)) ifTrue:[
5041
db886e8fb099 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5040
diff changeset
  4870
            "/ Transcript show:'T: '; showCR:node.
5048
8dbd0140a2f0 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5047
diff changeset
  4871
            "/ Transcript showCR:('Inside a ',(checkedNode className)).
5043
721c2ef8d1bb #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5042
diff changeset
  4872
            "/ self information:('Inside a ',(checkedNode className)).
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4873
            (checkedNode isMessage 
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4874
            and:[characterPositionOfCursor < (checkedNode selectorParts first start)]) ifTrue:[
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4875
                self codeCompletionForMessageTo:checkedNode receiver into:actionBlock.
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4876
                ^ self
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4877
            ]
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4878
            
4931
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4879
        ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4880
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4881
        checkedNode isMessage ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4882
            "/ completion in a message-send
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4883
            "/ Transcript showCR:'codeCompletionForMessage'.
4931
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4884
            self codeCompletionForMessage:checkedNode into:actionBlock.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4885
            ^ self
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4886
        ].
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4887
        checkedNode isMethod ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4888
            "/ completion in a method's selector pattern
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4889
            "/ Transcript showCR:'codeCompletionForMethodSpec'.
4931
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4890
            self codeCompletionForMethodSpec:checkedNode into:actionBlock.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4891
            ^ self.
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4892
        ].
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4893
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4894
4931
Claus Gittinger <cg@exept.de>
parents: 4926
diff changeset
  4895
        checkedNode := checkedNode parent.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4896
    ].
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4897
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4898
    "/ Transcript showCR:'Node is neither variable nor message'.
4352
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4899
    self information:'Node is neither variable nor message.'.
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4900
8e3e22043a75 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4350
diff changeset
  4901
    "Modified: / 04-07-2006 / 18:48:26 / fm"
5528
c514dd6f6e3b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5523
diff changeset
  4902
    "Modified: / 08-04-2017 / 16:01:14 / cg"
5900
880fa5a89fb8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5869
diff changeset
  4903
    "Modified: / 29-08-2018 / 16:43:14 / Claus Gittinger"
5040
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4904
!
f02e9db9841e #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5039
diff changeset
  4905
5070
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4906
withoutSelectorsUnlikelyFor:aClass from:selectorsArg forPartial:partialSelector
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4907
    "some heuristics;
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4908
     as best selectors has been chosen by implemented methods for aClass,
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4909
     some of them should be filtered (for example, at:/at:put:, which are
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4910
     found in object, but only make sense for variable objects or those which do
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4911
     implement at:put: themself.
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4912
     I have currently no better idea than hardcoding stuff I found irritating..."
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4913
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4914
    |selectors noNilChecks noIsXXXChecks noNoXXXChecks noBecome 
5112
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4915
     noIndexedSetters noIndexedGetters noSizeQueries docSelectors|
5070
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4916
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4917
    aClass isNil ifTrue:[ ^ selectorsArg ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4918
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4919
    noNilChecks := noIsXXXChecks := noNoXXXChecks := noBecome := false.
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4920
    noIndexedSetters := noIndexedGetters := noSizeQueries := false.
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4921
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4922
    selectors := (selectorsArg ? #()) asOrderedCollection.
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4923
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4924
    self tracePoint:#cg message:aClass.
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4925
5112
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4926
    aClass isMeta ifTrue:[
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4927
        docSelectors := #(copyright documentation examples 
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4928
                          version version_CVS version_SVN version_HG).
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4929
        selectors := selectors reject:[:sel | docSelectors includes:sel].
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4930
    ].
a25d288252f4 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5109
diff changeset
  4931
    
5070
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4932
    "/ actually meaning booleans here
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4933
    (aClass == True or:[aClass == False]) ifTrue:[
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4934
        noNilChecks := noBecome := true.
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4935
        (partialSelector startsWith:'is') ifFalse:[ noIsXXXChecks := true ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4936
        (partialSelector startsWith:'no') ifFalse:[ noNoXXXChecks := true ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4937
    ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4938
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4939
    (aClass includesBehavior: ArithmeticValue) ifTrue:[ noNilChecks := true ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4940
    (aClass includesBehavior: Symbol) ifTrue:[ noNilChecks := noBecome := noIndexedSetters := true ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4941
    (aClass includesBehavior: Number) ifTrue:[ noBecome := true ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4942
    (aClass includesBehavior: Block) ifTrue:[ noNilChecks := noIsXXXChecks := noNoXXXChecks := noBecome := true ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4943
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4944
    (aClass isMeta) ifTrue:[
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4945
        noNilChecks := noBecome := true.
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4946
        "/ remove messages which are only defined in Object and non-meta classes.
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4947
        selectors := selectors reject:
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4948
            [:sel |
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4949
                (Object implements:sel)
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4950
                and:[ (Smalltalk allImplementorsOf:sel) conform:[:impl | impl isMeta not]]
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4951
            ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4952
    ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4953
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4954
    aClass isVariable ifFalse:[
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4955
        noIndexedGetters := noIndexedSetters := noSizeQueries := true.
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4956
    ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4957
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4958
    noIndexedSetters ifTrue:[
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4959
        #( #'at:put:' #'basicAt:put:') do:[:indexAccessSelector |
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4960
            (aClass whichClassIncludesSelector:indexAccessSelector) == Object ifTrue:[
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4961
                selectors := selectors copyWithout:indexAccessSelector.
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4962
            ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4963
        ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4964
    ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4965
    noIndexedGetters ifTrue:[
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4966
        #( #'at:' #'basicAt:') do:[:indexAccessSelector |
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4967
            (aClass whichClassIncludesSelector:indexAccessSelector) == Object ifTrue:[
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4968
                selectors := selectors copyWithout:indexAccessSelector.
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4969
            ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4970
        ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4971
    ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4972
    noSizeQueries ifTrue:[
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4973
        #( #size #basicSize ) do:[:indexAccessSelector |
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4974
            (aClass whichClassIncludesSelector:indexAccessSelector) == Object ifTrue:[
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4975
                selectors := selectors copyWithout:indexAccessSelector.
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4976
            ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4977
        ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4978
    ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4979
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4980
    noNilChecks ifTrue:[
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4981
        selectors removeAllFoundIn:#(
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4982
                    'isNil' 'notNil'
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4983
                    'ifNil:' 'ifNotNil:' 'ifNil:ifNotNil:' 'ifNotNil:ifNil:' 'ifNotNilDo:'
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4984
                    'ifEmpty:' 'ifNotEmpty:' 'ifNotEmptyDo:' 'ifEmpty:ifNotEmpty:'
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4985
                    'ifEmpty:ifNotEmptyDo:' 'ifNotEmptyDo:ifEmpty:' 'ifEmptyDo:ifNotEmpty:'
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4986
                  ).
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4987
    ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4988
    noIsXXXChecks ifTrue:[
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4989
        "/ get rid of all isXXX selectors
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4990
        selectors := selectors reject:[:sel | sel startsWith:'is'].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4991
    ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4992
    noNoXXXChecks ifTrue:[
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4993
        "/ get rid of all notXXX selectors
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4994
        selectors := selectors reject:[:sel | sel startsWith:'no'].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4995
    ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4996
    noBecome ifTrue:[
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4997
        "/ get rid of all become* selectors
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4998
        selectors := selectors reject:[:sel | sel startsWith:'become'].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  4999
        selectors remove:#oneWayBecome: ifAbsent:[].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  5000
        selectors := selectors reject:[:sel | sel startsWith:'changeClassTo'].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  5001
    ].
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  5002
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  5003
    "/ actually: directly implemented selectors are more likely, so move them to top
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  5004
    selectors := (selectors select:[:sel | aClass implements:sel])
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  5005
                 ,
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  5006
                 (selectors reject:[:sel | aClass implements:sel]).
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  5007
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  5008
    ^ selectors
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  5009
! !
8277d17c3e50 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5064
diff changeset
  5010
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5011
!DoWhatIMeanSupport methodsFor:'code completion-helpers-old'!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5012
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5013
codeCompletionForLiteralSymbol:node inClass:classOrNil codeView:codeView
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5014
    |sym possibleCompletions best start stop oldLen newLen oldVar|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5015
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5016
    sym := node value.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5017
    possibleCompletions := OrderedCollection new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5018
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5019
    Symbol allInstancesDo:[:existingSym |
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  5020
	(existingSym startsWith:sym) ifTrue:[
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  5021
	    (existingSym = sym) ifFalse:[
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  5022
		possibleCompletions add:existingSym
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  5023
	    ].
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  5024
	].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5025
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5026
    possibleCompletions sort.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5027
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5028
    best := possibleCompletions longestCommonPrefix.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5029
    (best = sym or:[(possibleCompletions includes:best) not]) ifTrue:[
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  5030
	best := self askUserForCompletion:'symbol literal' for:codeView at: node start from:possibleCompletions.
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  5031
	best isNil ifTrue:[^ self].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5032
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5033
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5034
"/ self showInfo:best.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5035
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5036
    start := node start.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5037
    stop := node stop.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5038
    (codeView characterAtCharacterPosition:start) == $# ifTrue:[
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  5039
	start := start + 1.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5040
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5041
    (codeView characterAtCharacterPosition:start) == $' ifTrue:[
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  5042
	start := start + 1.
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  5043
	stop := stop - 1.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5044
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5045
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5046
    oldVar := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5047
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5048
    codeView
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  5049
	undoableDo:[ codeView replaceFromCharacterPosition:start to:stop with:best ]
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  5050
	info:'Completion'.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5051
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5052
    (best startsWith:oldVar) ifTrue:[
5542
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  5053
	oldLen := stop - start + 1.
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  5054
	newLen := best size.
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  5055
	codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
27dfb346d0cb #DOCUMENTATION by mawalch
mawalch
parents: 5539
diff changeset
  5056
	codeView dontReplaceSelectionOnInput
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5057
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5058
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5059
    "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
  5060
    "Modified (format): / 03-07-2011 / 15:58:45 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5061
!
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5062
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5063
codeCompletionForMessage:node inClass:classOrNil instance:instanceOrNil context:contextOrNil codeView:codeView
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  5064
    "going to be OBSOLETE"
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  5065
    
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5066
    |selector
4547
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  5067
     bestSelectors selector2 bestSelectors2 bestSelectorsFromRB allBest best numArgs
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5068
     newParts nSelParts oldLen newLen selectorParts
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5069
     findBest parentNode selectorInBest selector2InBest2
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  5070
     parser selectorsSentInCode selectorsImplementedInClass
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  5071
     varName rbTypes rbType tryParent parentIsKeywordMessage parentIsBinaryMessage rcvrClass|
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5072
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5073
    RefactoryTyper notNil ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5074
        "/ refactory package also provides a (very limited) typer;
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5075
        "/ 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
  5076
        (node receiver isVariable) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5077
            varName := node receiver name.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5078
            varName isUppercaseFirst ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5079
            ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5080
                tree := RBParser
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5081
                            parseMethod:codeView contents string
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5082
                            onError:[:aString :pos | nil].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5083
                tree notNil ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5084
                    rbTypes := RefactoryTyper
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5085
                                classesFor: varName
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5086
                                in: tree
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5087
                                model: nil
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5088
                                ignoredSelectors:(Array with:node selector).
6013
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  5089
                    rbTypes size ~~ 0 ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5090
                        rbTypes size > 1 ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5091
                            rbTypes remove:ProtoObject ifAbsent:[].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5092
                            rbTypes remove:Autoload ifAbsent:[].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5093
                            rbTypes remove:ObsoleteObject ifAbsent:[].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5094
                        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5095
                        rbTypes size == 1 ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5096
                            rbType := rbTypes first.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5097
                        ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5098
                            rbType := Class commonSuperclassOf:rbTypes
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5099
                        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5100
                        (rbType notNil "and:[rbType ~= Object]") ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5101
                            bestSelectorsFromRB := Parser findBest:30 selectorsFor:node selector in:rbType forCompletion:true.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5102
                        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5103
                    ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5104
                ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5105
            ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5106
        ].
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5107
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5108
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5109
    classOrNil notNil ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5110
        parser := Parser parseMethod:codeView contents string in:classOrNil ignoreErrors:true ignoreWarnings:true.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5111
        selectorsSentInCode := parser messagesSent.
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5112
    ].
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5113
    classOrNil notNil ifTrue:[
4936
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  5114
        selectorsImplementedInClass := Set new.
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  5115
        classOrNil withAllSuperclassesDo:[:cls |
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  5116
            cls theNonMetaclass ~~ Object ifTrue:[
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  5117
                selectorsImplementedInClass addAll:cls selectors.
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  5118
            ]
486789a85cea #FEATURE
Claus Gittinger <cg@exept.de>
parents: 4934
diff changeset
  5119
        ]    
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5120
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5121
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5122
    findBest := [:node :selector |
5035
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  5123
        |srchClasses bestSelectors bestPrefixes|
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5124
4933
9801e2eea4c7 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  5125
        codeView withCursor:(Cursor questionMark) do:[
5035
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  5126
            srchClasses := self classesOfNode:node receiver.
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  5127
            srchClasses notNil ifTrue:[
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  5128
                bestSelectors := Set new.
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  5129
                srchClasses do:[:each |
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  5130
                    bestSelectors addAll:(Parser findBest:30 selectorsFor:selector in:each forCompletion:true).
5afe663f6f8d #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5033
diff changeset
  5131
                ]    
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5132
            ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5133
                bestSelectors := Parser findBest:30 selectorsFor:selector in:nil forCompletion:true.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5134
            ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5135
        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5136
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5137
        (bestSelectors includes:selector) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5138
            bestSelectors := bestSelectors select:[:sel | sel size > selector size].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5139
        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5140
        bestSelectors
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5141
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5142
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5143
    selector := node selector.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5144
    bestSelectors := findBest value:node value:selector.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5145
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5146
    parentNode := node parent.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5147
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5148
    parentIsKeywordMessage :=
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5149
        (parentNode notNil
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5150
            and:[ parentNode isMessage
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  5151
            and:[ parentNode selector isKeyword]]).
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  5152
    parentIsBinaryMessage :=
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5153
        (parentNode notNil
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5154
            and:[ parentNode isMessage
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5155
            and:[ parentNode selector isBinarySelector]]).
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5156
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5157
    tryParent := false.
5471
289b60e70a2c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5462
diff changeset
  5158
    "/ if it's 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
  5159
    (node selector isUnarySelector and:[ parentIsKeywordMessage ]) ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5160
        tryParent := true.
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5161
    ] ifFalse:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5162
        "/ 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
  5163
        (node isMessage
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5164
        and:[ node receiver isMessage
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5165
        and:[ node receiver receiver isVariable
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5166
        and:[ node receiver receiver name isUppercaseFirst
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5167
        and:[ #(new new:) includes:(selector2 := node receiver selector) ]]]]) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5168
            rcvrClass := Smalltalk classNamed:(node receiver receiver name).
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5169
            "/ srchClass2 := self lookupClassForMessage:parentNode inClass:classOrNil.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5170
            bestSelectors := Parser findBest:30 selectorsFor:selector in:rcvrClass forCompletion:true.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5171
        ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5172
            "/ also, if nothing was found
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5173
            (bestSelectors isEmpty
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5174
            and:[ parentNode notNil
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5175
            and:[ parentNode isMessage ]]) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5176
                "/ srchClass2 := self lookupClassForMessage:parentNode inClass:classOrNil.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5177
                "/ selector2 := parentNode selector.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5178
                "/ selector2 := selector2,selector.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5179
                bestSelectors := findBest value:parentNode value:selector.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5180
            ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5181
        ]
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5182
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5183
    tryParent ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5184
        selector2 := parentNode selector,selector.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5185
        bestSelectors2 := findBest value:parentNode value:selector2.
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5186
    ].
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  5187
    bestSelectorsFromRB notEmptyOrNil ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5188
        bestSelectors := bestSelectorsFromRB , (bestSelectors reject:[:sel | bestSelectorsFromRB includes:sel]).
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  5189
    ].
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5190
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5191
    "/ if the parent is a keyword selector, the child cannot
4346
e70115a3a9e6 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4345
diff changeset
  5192
    (parentIsKeywordMessage or:[parentIsBinaryMessage]) ifTrue:[
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  5193
        bestSelectors := bestSelectors reject:[:sel | sel isKeyword]
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5194
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5195
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5196
    bestSelectors2 isEmptyOrNil ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5197
        allBest := bestSelectors.
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5198
    ] ifFalse:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5199
        bestSelectors isEmptyOrNil ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5200
            allBest := bestSelectors2
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5201
        ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5202
            selectorInBest := (bestSelectors contains:[:sel | sel asLowercase startsWith:selector asLowercase]).
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5203
            selector2InBest2 := (bestSelectors2 contains:[:sel | sel asLowercase startsWith:selector2 asLowercase]).
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5204
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5205
            (selectorInBest not and:[ selector2InBest2 ]) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5206
                "/ selector2 is more likely
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5207
                allBest := bestSelectors2
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5208
            ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5209
                (selectorInBest and:[ selector2InBest2 not ]) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5210
                    "/ selector more likely
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5211
                    allBest := bestSelectors
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5212
                ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5213
                    "/ assume same likelyness
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5214
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5215
                    allBest := bestSelectors isEmpty
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5216
                                ifTrue:[ bestSelectors2 ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5217
                                ifFalse:[ bestSelectors , #(nil) , bestSelectors2 ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5218
                ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5219
            ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5220
        ].
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5221
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5222
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5223
    allBest isEmptyOrNil ifTrue:[ ^ self ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5224
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5225
    selectorsImplementedInClass notNil ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5226
        "/ the ones implemented in the receiver class are moved to the top of the list.
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  5227
        allBest := self 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  5228
                    splitSelectorList:allBest 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  5229
                    by:[:sel | selectorsImplementedInClass includes:sel].
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5230
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5231
    selectorsSentInCode notNil ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5232
        "/ the ones already sent in the code are moved to the top of the list.
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  5233
        allBest := self 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  5234
                    splitSelectorList:allBest 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  5235
                    by:[:sel | selectorsSentInCode includes:sel].
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5236
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5237
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5238
    "/ the ones which are a prefix are moved towards the top of the list
5044
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  5239
    allBest := self 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  5240
                splitSelectorList:allBest 
f8c330427edc #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5043
diff changeset
  5241
                by:[:sel | sel notNil and:[sel startsWith:selector]].
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5242
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5243
    best := allBest first.
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5244
    allBest size > 1 ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5245
        "allBest size < 20 ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5246
            |idx|
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5247
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5248
            idx := (PopUpMenu labels:allBest) startUp.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5249
            idx == 0 ifTrue:[ ^ self].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5250
            best := allBest at:idx.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5251
        ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5252
            allBest remove:nil ifAbsent:[].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5253
            best := Dialog request:'Matching selectors:' initialAnswer:best list:allBest.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5254
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5255
        ]."
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5256
        allBest remove:nil ifAbsent:[].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5257
        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
  5258
        best isEmptyOrNil ifTrue:[^ self].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5259
        best = '-' ifTrue:[^ self].
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5260
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5261
4547
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  5262
"/    srchClass notNil ifTrue:[
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  5263
"/        implClass := srchClass whichClassIncludesSelector:best.
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  5264
"/    ] ifFalse:[
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  5265
"/        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
  5266
"/        implClass size == 1 ifTrue:[
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  5267
"/            implClass := implClass first.
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  5268
"/        ] ifFalse:[
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  5269
"/            implClass := nil
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  5270
"/        ]
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  5271
"/    ].
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  5272
"/
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  5273
"/    info := best storeString.
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  5274
"/    implClass notNil ifTrue:[
6022
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
  5275
"/        info := implClass name , ' » ' , info.
4547
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  5276
"/    ].
4cec3ca730ed class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4545
diff changeset
  5277
"/    self information:info.
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5278
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5279
    best ~= selector ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5280
        numArgs := best numArgs.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5281
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5282
        (bestSelectors2 notEmptyOrNil and:[bestSelectors2 includes:best]) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5283
            selectorParts := parentNode selectorParts , node selectorParts.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5284
        ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5285
            selectorParts := node selectorParts.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5286
        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5287
        nSelParts := selectorParts size.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5288
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5289
        newParts := best asCollectionOfSubstringsSeparatedBy:$:.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5290
        newParts := newParts select:[:part | part size > 0].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5291
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5292
        codeView
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5293
            undoableDo:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5294
                |newCursorPosition stop|
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5295
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5296
                numArgs > nSelParts ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5297
                    stop := selectorParts last stop.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5298
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5299
                    "/ append the rest ...
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5300
                    numArgs downTo:nSelParts+1 do:[:idx |
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5301
                        |newPart|
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5302
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5303
                        newPart := newParts at:idx.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5304
                        (best endsWith:$:) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5305
                            newPart := newPart , ':'
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5306
                        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5307
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5308
                        (codeView characterAtCharacterPosition:stop) == $: ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5309
                            newPart := ':' , newPart.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5310
                        ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5311
                        newPart := (codeView characterAtCharacterPosition:stop) asString , newPart.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5312
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5313
                        codeView replaceFromCharacterPosition:stop to:stop with:newPart.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5314
                        newCursorPosition := stop + newPart size.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5315
                    ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5316
                ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5317
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5318
                (nSelParts min:newParts size) downTo:1 do:[:idx |
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5319
                    |newPart oldPartialToken start stop nextChar|
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5320
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5321
                    newPart := newParts at:idx.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5322
                    oldPartialToken := selectorParts at:idx.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5323
                    start := oldPartialToken start.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5324
                    stop := oldPartialToken stop.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5325
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  5326
                    (best isKeyword) ifTrue:[
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5327
                        (oldPartialToken value endsWith:$:) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5328
                            newPart := newPart , ':'
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5329
                        ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5330
                            (codeView characterAtCharacterPosition:stop+1) == $: ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5331
                                newPart := newPart , ':'
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5332
                            ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5333
                        ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5334
                    ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5335
                        (codeView characterAtCharacterPosition:stop) == $: ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5336
                            newPart := newPart , ':'
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5337
                        ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5338
                            nextChar := codeView characterAtCharacterPosition:stop+1.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5339
                            nextChar isSeparator ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5340
                                (').' includes:nextChar) ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5341
                                    newPart := newPart , ' '
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5342
                                ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5343
                            ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5344
                        ]
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5345
"/                            codeView replaceFromCharacterPosition:start to:stop with:(newPart , ':').
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5346
"/                        ] ifFalse:[
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5347
"/                            codeView replaceFromCharacterPosition:start to:stop with:newPart.
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5348
                    ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5349
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5350
                    codeView replaceFromCharacterPosition:start to:stop with:newPart.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5351
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5352
                    "/ codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5353
                    newCursorPosition isNil ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5354
                        oldLen := stop - start + 1.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5355
                        newLen := newPart size.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5356
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5357
                        newCursorPosition := stop + (newLen-oldLen)
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5358
                    ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5359
                ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5360
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5361
                codeView cursorToCharacterPosition:newCursorPosition.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5362
                codeView cursorRight.  "/ avoid going to the next line !!
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5363
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5364
                ((best endsWith:':') and:[numArgs == 1]) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5365
                    |impls impl|
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5366
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5367
                    "/ see if it expects a block argument (heuristic)
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5368
                    best := best asSymbol.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5369
                    (node notNil
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5370
                    and:[classOrNil notNil
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5371
                    and:[node receiver isSelf]]) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5372
                        (impl := classOrNil whichClassImplements:best) isNil ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5373
                            impls := #().
5687
c5be8b9eff20 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5660
diff changeset
  5374
                            Screen current beepInEditor.
4710
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5375
                        ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5376
                            impls := { impl }
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5377
                        ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5378
                    ] ifFalse:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5379
                        impls := Smalltalk allImplementorsOf:best.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5380
                    ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5381
                    (impls contains:[:cls |
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5382
                        |argName|
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5383
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5384
                        argName := ((cls compiledMethodAt:best) methodArgAndVarNames at:1) asLowercase.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5385
                        (argName includesString:'block') or:[ (argName includesString:'action')]]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5386
                    ) ifTrue:[
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5387
                        codeView insertStringAtCursor:'['
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5388
                    ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5389
                ].
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5390
                codeView dontReplaceSelectionOnInput.
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5391
            ]
94634917ce8f class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4691
diff changeset
  5392
        info:'Completion'.
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5393
    ].
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5394
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5395
    "Created: / 10-11-2006 / 13:18:27 / cg"
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5396
    "Modified: / 16-02-2010 / 10:33:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
5038
137974a28198 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5035
diff changeset
  5397
    "Modified: / 30-04-2016 / 18:21:21 / cg"
5471
289b60e70a2c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5462
diff changeset
  5398
    "Modified (comment): / 13-02-2017 / 20:37:55 / cg"
6013
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  5399
    "Modified: / 01-03-2019 / 14:53:00 / Claus Gittinger"
4345
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5400
!
a510223345e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4344
diff changeset
  5401
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5402
codeCompletionForVariable:node inClass:classOrNil codeView:codeView
4277
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  5403
    |parent nonMetaClass crsrPos nm
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5404
     allVariables allDistances best nodeVal
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5405
     char start stop oldLen newLen oldVar
4485
c6ed849af389 class: DoWhatIMeanSupport
Stefan Vogel <sv@exept.de>
parents: 4484
diff changeset
  5406
     getDistanceComputeBlockWithWeight addWithFactorBlock allTheBest bestAssoc
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5407
     globalFactor localFactor selectorOfMessageToNode tree implementors argIdx namesUsed kwPart|
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5408
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5409
    classOrNil notNil ifTrue:[
5253
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5410
        nonMetaClass := classOrNil theNonMetaclass.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5411
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5412
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5413
    nm := node name.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5414
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5415
    "/ 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
  5416
    "/ the user is probably looking for a message selector.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5417
    "/ If the variable represents a global, present its instance creation messages
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5418
    crsrPos := codeView characterPositionOfCursor.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5419
    char := codeView characterAtCharacterPosition:crsrPos-1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5420
    char isSeparator ifTrue:[
5253
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5421
        classOrNil isNil ifTrue:[
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5422
            nodeVal := Smalltalk at:nm asSymbol.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5423
        ] ifFalse:[
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5424
            nodeVal := classOrNil topNameSpace at:nm asSymbol ifAbsent:[Smalltalk at:nm asSymbol].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5425
        ].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5426
        nodeVal isBehavior ifTrue:[
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5427
            |methods menu exitKey idx|
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5428
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5429
            methods := nodeVal class methodDictionary values
6022
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
  5430
                            select:[:m | 
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
  5431
                                |cat|
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
  5432
                                cat := m category.
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
  5433
                                cat notNil
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
  5434
                                and:[cat sameAs:'instance creation']
5253
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5435
                            ].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5436
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5437
            menu := PopUpMenu labels:(methods collect:[:each | each selector]).
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5438
            menu hideOnKeyFilter:[:key | |hide|
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5439
                    hide := ( #( CursorDown CursorUp Escape Return ) includes: key) not.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5440
                    hide ifTrue:[
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5441
                        exitKey := key.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5442
                    ].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5443
                    hide].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5444
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5445
            idx := menu startUp.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5446
            idx == 0 ifTrue:[
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5447
                exitKey notNil ifTrue:[
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5448
                    codeView keyPress:exitKey x:0 y:0.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5449
                ].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5450
                ^ self
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5451
            ].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5452
            best := (methods at:idx) selector.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5453
            codeView
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5454
                undoableDo:[
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5455
                    codeView insertString:best atCharacterPosition:crsrPos.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5456
                    codeView cursorToCharacterPosition:crsrPos+best size.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5457
                ]
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5458
                info:'completion'.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5459
            ^ self.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5460
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5461
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5462
4277
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  5463
    ((parent := node parent) notNil and:[parent isMessage]) ifTrue:[
5253
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5464
        node == parent receiver ifTrue:[
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5465
            selectorOfMessageToNode := parent selector
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5466
        ]
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5467
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5468
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5469
    getDistanceComputeBlockWithWeight :=
5253
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5470
        [:weight |
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5471
            [:each |
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5472
                |dist factor|
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5473
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5474
                dist := each spellAgainst:nm.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5475
                factor := 1.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5476
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5477
                (each startsWith:nm) ifTrue:[
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5478
                    factor := 6 * nm size.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5479
                ] ifFalse:[
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5480
                    (each asLowercase startsWith:nm asLowercase) ifTrue:[
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5481
                        factor := 4 * nm size.
5360
b258afc07129 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5324
diff changeset
  5482
                    ] ifFalse:[
b258afc07129 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5324
diff changeset
  5483
                        (each endsWith:nm) ifTrue:[
b258afc07129 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5324
diff changeset
  5484
                            factor := 3 * nm size.
b258afc07129 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5324
diff changeset
  5485
                        ] ifFalse:[
b258afc07129 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5324
diff changeset
  5486
                            (each asLowercase endsWith:nm asLowercase) ifTrue:[
b258afc07129 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5324
diff changeset
  5487
                                factor := 2 * nm size.
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  5488
                            ]
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  5489
                        ]
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  5490
                    ]
5253
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5491
                ].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5492
                dist := dist + (weight*factor).
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5493
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5494
                each -> (dist * weight)
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5495
             ]
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5496
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5497
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5498
    addWithFactorBlock :=
6022
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
  5499
        [:eachNames :factor | 
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
  5500
            |namesToAdd|
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
  5501
5253
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5502
            namesToAdd := eachNames select:[:nameToAdd | nameToAdd ~= nm ].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5503
            namesToAdd := namesToAdd reject:[:each | allVariables includes:each ].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5504
            allVariables addAll:namesToAdd.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5505
            allDistances addAll:(namesToAdd collect:(getDistanceComputeBlockWithWeight value:factor)).
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5506
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5507
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5508
    nm isUppercaseFirst ifTrue:[
5253
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5509
        globalFactor := 2.    "/ favour globals
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5510
        localFactor := 1.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5511
    ] ifFalse:[
5253
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5512
        globalFactor := 1.    "/ favour locals
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5513
        localFactor := 2.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5514
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5515
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5516
    allVariables := OrderedCollection new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5517
    allDistances := OrderedCollection new.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5518
4308
f1c31624744d class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4304
diff changeset
  5519
    "/ are we in the method's selector spec ?
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5520
    ((parent := node parent) notNil
4277
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  5521
    and:[parent isMethod
d55287081b53 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  5522
    and:[parent arguments includes:node]]) ifTrue:[
5253
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5523
        "/ now that's cool: look how the naem of this argument is in other implementations
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5524
        "/ of this method, and take that as a basis of the selection
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5525
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5526
        implementors := SystemBrowser
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5527
                            findImplementorsOf:(parent selector)
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5528
                            in:(Smalltalk allClasses)
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5529
                            ignoreCase:false.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5530
        "/ which argument is it
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5531
        argIdx := parent arguments indexOf:node.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5532
        implementors size > 50 ifTrue:[
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5533
            implementors := implementors asOrderedCollection copyTo:50.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5534
        ].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5535
        namesUsed := implementors
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5536
                        collect:[:eachImplementor |
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5537
                            |parseTree|
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5538
                            parseTree := eachImplementor parseTree.
6013
36f85fdcc2eb #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5980
diff changeset
  5539
                            (parseTree notNil and:[parseTree arguments size ~~ 0])
5253
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5540
                                ifFalse:nil
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5541
                                ifTrue:[ (parseTree arguments at:argIdx) name] ]
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5542
                        thenSelect:[:a | a notNil] as:Set.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5543
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5544
        addWithFactorBlock value:namesUsed value:(2 * localFactor).
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5545
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5546
        classOrNil notNil ifTrue:[
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5547
            "/ also, look for the keyword before the argument,
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5548
            "/ and see if there is such an instVar
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5549
            "/ if so, add it with -Arg
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5550
            parent selector isKeyword ifTrue:[
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5551
                kwPart := parent selector keywords at:argIdx.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5552
                (classOrNil allInstVarNames includes:(kwPart copyButLast:1)) ifTrue:[
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5553
                    addWithFactorBlock
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5554
                        value:(classOrNil allInstVarNames collect:[:nm| nm,'Arg'])
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5555
                        value:(1 * localFactor).
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5556
                ].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5557
            ].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5558
        ]
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5559
    ] ifFalse:[
5253
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5560
        classOrNil notNil ifTrue:[
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5561
            "/ locals in the block/method
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5562
            |names|
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5563
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5564
            names := node allVariablesOnScope.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5565
            "/ if there were no variables (due to a parse error)
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5566
            "/ do another parse and see what we have
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5567
            names isEmpty ifTrue:[
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5568
                tree := self treeForCode:(codeView contentsAsString string) allowErrors:true.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5569
                "/ better if we already have a body (include locals then)
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5570
                "/ otherwise, only the arguments are considered
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5571
                tree notNil ifTrue:[
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5572
                    names := (tree body ? tree) allVariablesOnScope.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5573
                ]
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5574
            ].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5575
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5576
            addWithFactorBlock value:names value:(4 * localFactor).
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5577
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5578
            "/ instance variables
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5579
            addWithFactorBlock value:classOrNil instVarNames value:(3 * localFactor).
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5580
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5581
            "/ inherited instance variables
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5582
            classOrNil superclass notNil ifTrue:[
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5583
                addWithFactorBlock value:classOrNil superclass allInstVarNames value:(2.5 * localFactor).
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5584
            ].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5585
        ].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5586
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5587
        selectorOfMessageToNode notNil ifTrue:[
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5588
            |names responders nonResponders|
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5589
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  5590
            "/ responding to that message
5253
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5591
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5592
            classOrNil notNil ifTrue:[
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5593
                "/ private classes
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5594
                addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix])
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5595
                                   value:(1.75 * globalFactor).
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5596
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5597
                "/ class variables
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5598
                names := nonMetaClass classVarNames.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5599
                responders := names select:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5600
                nonResponders := names reject:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5601
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5602
                addWithFactorBlock value:responders value:(1.5 * globalFactor).
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5603
                addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5604
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5605
                "/ superclass var names
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5606
                nonMetaClass allSuperclassesDo:[:superClass |
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5607
                    names := superClass classVarNames.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5608
                    responders := names select:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5609
                    nonResponders := names reject:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5610
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5611
                    addWithFactorBlock value:responders value:(1 * globalFactor).
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5612
                    addWithFactorBlock value:nonResponders value:(0.5 * 1 * globalFactor).
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5613
                ].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5614
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5615
                "/ namespace vars
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5616
                classOrNil nameSpace ~~ Smalltalk ifTrue:[
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5617
                    names := classOrNil topNameSpace keys.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5618
                    names := names reject:[:nm | nm includes:$:].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5619
                    names := names select:[:nm | nm isUppercaseFirst ].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5620
                    responders := names select:[:nsVar | |c| c := classOrNil topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5621
                    nonResponders := names reject:[:nsVar | |c| c := classOrNil topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5622
                    addWithFactorBlock value:responders value:(1.5 * globalFactor).
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5623
                    addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5624
                ].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5625
            ].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5626
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5627
            "/ globals
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5628
            names := Smalltalk keys.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5629
            "/ names := names reject:[:nm | nm includes:$:].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5630
            names := names select:[:nm | nm isUppercaseFirst ].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5631
            responders := names select:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5632
            nonResponders := names reject:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5633
            addWithFactorBlock value:responders value:(1.5 * globalFactor).
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5634
            addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor).
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5635
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5636
            "/ pool variables
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5637
            classOrNil theNonMetaclass sharedPoolNames do:[:poolName |
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5638
                |pool|
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5639
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5640
                pool := Smalltalk at:poolName.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5641
                names := pool classVarNames.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5642
                names := names select:[:nm | nm isUppercaseFirst ].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5643
                responders := names select:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5644
                nonResponders := names reject:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5645
                addWithFactorBlock value:responders value:(2.5 * globalFactor).
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5646
                addWithFactorBlock value:nonResponders value:(0.5 * 2.5 * globalFactor).
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5647
            ].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5648
        ] ifFalse:[
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5649
            |names|
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5650
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5651
            classOrNil notNil ifTrue:[
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5652
                "/ private classes
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5653
                addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix])
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5654
                                   value:(1.75 * globalFactor).
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5655
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5656
                "/ class variables
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5657
                addWithFactorBlock value:nonMetaClass classVarNames value:(2.0 * globalFactor).
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5658
                classOrNil superclass notNil ifTrue:[
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5659
                    addWithFactorBlock value:nonMetaClass superclass allClassVarNames value:(2.0 * globalFactor).
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5660
                ].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5661
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5662
                "/ namespace vars
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5663
                classOrNil nameSpace ~~ Smalltalk ifTrue:[
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5664
                    names := classOrNil nameSpace isNameSpace ifTrue:[classOrNil nameSpace keys] ifFalse:[classOrNil nameSpace privateClasses collect:[:c | c nameWithoutPrefix]].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5665
                    names := names select:[:nm | nm isUppercaseFirst ].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5666
                    addWithFactorBlock value:names value:(1.5 * globalFactor).
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5667
                ].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5668
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5669
                "/ pool variables
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5670
                classOrNil theNonMetaclass sharedPoolNames do:[:poolName |
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5671
                    |pool|
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5672
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5673
                    pool := Smalltalk at:poolName.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5674
                    names := pool classVarNames.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5675
                    addWithFactorBlock value:names value:(2.5 * globalFactor).
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5676
                ].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5677
            ].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5678
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5679
            "/ globals
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5680
            names := Smalltalk keys.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5681
            names := names select:[:nm | nm isUppercaseFirst ].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5682
            addWithFactorBlock value:names value:(1.5 * globalFactor).
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5683
        ].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5684
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5685
        "/ pseudos - assuming that thisContext is seldom used.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5686
        "/ also assuming, that nil is short so its usually typed in.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5687
        addWithFactorBlock value:#('self') value:(2.5 * localFactor).
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5688
        addWithFactorBlock value:#('nil') value:(0.5 * localFactor).
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5689
        addWithFactorBlock value:#('super' 'false') value:(2 * localFactor).
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5690
        addWithFactorBlock value:#('thisContext') value:(1 * localFactor).
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5691
        addWithFactorBlock value:#('true') value:(1 * localFactor).
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5692
        addWithFactorBlock value:#('false') value:(1 * localFactor).
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5693
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5694
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5695
    allDistances isEmpty ifTrue:[^ self].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5696
    bestAssoc := allDistances at:1.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5697
    bestAssoc := allDistances inject:bestAssoc into:[:el :best | el value > best value
5253
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5698
                                                           ifTrue:[el]
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5699
                                                           ifFalse:[best]
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5700
                                                    ].
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5701
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5702
    allDistances sort:[:a :b |
5253
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5703
                                a value > b value ifTrue:[
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5704
                                    true
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5705
                                ] ifFalse:[
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5706
                                    a value = b value ifTrue:[
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5707
                                        a key < b key
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5708
                                    ] ifFalse:[
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5709
                                        false
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5710
                                    ]
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5711
                                ]
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5712
                      ].
4340
b7b73a78385a class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4339
diff changeset
  5713
    ((allTheBest := allDistances) count:[:entry | entry value]) > 20 ifTrue:[
5253
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5714
        allTheBest := allDistances select:[:entry | entry value >= (bestAssoc value * 0.5)].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5715
        allTheBest size > 15 ifTrue:[
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5716
            allTheBest := allDistances select:[:entry | entry value >= (bestAssoc value * 0.8)].
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5717
        ].
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5718
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5719
4524
54079876ac80 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4488
diff changeset
  5720
    start := node start.
54079876ac80 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4488
diff changeset
  5721
    stop := node stop.
54079876ac80 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4488
diff changeset
  5722
4548
a5f0ea5916a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4547
diff changeset
  5723
    best := self askUserForCompletion:('Variable for "%1"' bindWith:node name)
5253
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5724
                 for:codeView at: start
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5725
                 from:(allTheBest collect:[:assoc | assoc key]).
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5726
    best isNil ifTrue:[^ self].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5727
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5728
"/ self showInfo:best.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5729
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5730
    oldVar := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators.
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5731
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5732
    codeView
5253
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5733
        undoableDo:[ codeView replaceFromCharacterPosition:start to:stop with:best ]
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5734
        info:'Completion'.
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5735
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5736
    (best startsWith:oldVar) ifTrue:[
5253
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5737
        oldLen := stop - start + 1.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5738
        newLen := best size.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5739
        codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1.
43b16e24a811 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5225
diff changeset
  5740
        codeView dontReplaceSelectionOnInput
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5741
    ].
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5742
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5743
    "Created: / 10-11-2006 / 13:16:33 / cg"
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5744
    "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
  5745
    "Modified: / 28-08-2013 / 15:37:28 / cg"
5551
69c688e4d25b #DOCUMENTATION by mawalch
mawalch
parents: 5542
diff changeset
  5746
    "Modified (format): / 12-06-2017 / 12:37:31 / mawalch"
6022
ccbc2453e82d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6013
diff changeset
  5747
    "Modified (format): / 03-03-2019 / 22:53:58 / Claus Gittinger"
4238
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5748
! !
c4399aff7359 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5749
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5750
!DoWhatIMeanSupport methodsFor:'helpers-naive type inference'!
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5751
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5752
addClassesFromAssignmentTo:varName in:aTree to:setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5753
    "/ assignments...
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5754
    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5755
    aTree allAssignmentNodesDo:[:eachAssignmentNode |
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5756
        |leftSide|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5757
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5758
        leftSide := eachAssignmentNode variable.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5759
        leftSide name = varName ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5760
            self 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5761
                addClassesOfExpression:eachAssignmentNode value 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5762
                inClass:classOrNil to:setOfTypes.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5763
        ]
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5764
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5765
    ^ setOfTypes.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5766
!
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5767
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5768
addClassesFromMessagesSentTo:varNode in:aTree to:setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5769
    "/ from the set of messages sent at other places,
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5770
    "/ try to find classes, which respond to all those.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5771
    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5772
    |varName allSelectors candidates|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5773
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5774
    varName := varNode name.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5775
    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5776
    allSelectors := IdentitySet new.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5777
    aTree allMessageNodesDo:[:eachMessageNode |
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5778
        |rcvr|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5779
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5780
        rcvr := eachMessageNode receiver.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5781
        (rcvr isVariable and:[rcvr name = varName]) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5782
            allSelectors add:eachMessageNode selector
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5783
        ]
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5784
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5785
    
5324
555436a71f8d #OTHER by mawalch
mawalch
parents: 5322
diff changeset
  5786
    "/ the selector being completed must be ignored here
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5787
    (varNode parent notNil and:[varNode parent isMessage]) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5788
        allSelectors remove:(varNode parent selector) ifAbsent:[].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5789
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5790
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5791
    "/ now look for classes which implement all of them
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5792
    candidates := SystemBrowser findRespondersOfAll:allSelectors in:nil ignoreCase:false.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5793
    candidates remove:Object ifAbsent:[].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5794
    setOfTypes addAll:candidates.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5795
    ^ setOfTypes.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5796
!
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5797
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5798
addClassesOfBlockVarForWellknownBlocks:variableNode inScope:blockScope to:setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5799
    |blockParent blockParentSelector exNode isHandler|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5800
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5801
    blockParent := blockScope parent.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5802
    (blockParent notNil and:[blockParent isMessage]) ifFalse:[^ setOfTypes].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5803
    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5804
    blockParentSelector := blockParent selector.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5805
    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5806
    "/ if the parent of the block is an enumeration message, and the receiver is known,
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5807
    "/ we know the type of argument.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5808
    ( #(do: keysAndValuesDo: select: collect:) includes:blockParent selector) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5809
        |collection|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5810
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5811
        collection := self valueOfNode:blockParent receiver.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5812
        collection notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5813
            (collection isKindOf:Collection) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5814
                collection notEmpty ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5815
                    |someElement|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5816
                    someElement := collection anElement.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5817
                    setOfTypes add:someElement class.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5818
                    ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5819
                ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5820
            ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5821
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5822
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5823
    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5824
    "/ because we type-in those so often, it is great to get
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5825
    "/ better info on the ex parameter... (and it's a low hanging fruit)
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5826
    ( blockParentSelector == #handle:do: ) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5827
        exNode := blockParent receiver.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5828
        isHandler := (blockScope == (blockParent arguments at:1)).
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5829
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5830
    ( blockParentSelector == #on:do: ) ifTrue:[
5133
ea59e0c6f090 #BUGFIX by Maren
matilk
parents: 5131
diff changeset
  5831
"/        self halt.
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5832
        exNode := blockParent arg1.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5833
        isHandler := (blockScope == (blockParent arguments at:2)).
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5834
    ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5835
    exNode notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5836
        |cls exClass|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5837
        
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5838
        ((cls := (self valueOfNode:exNode)) notNil and:[cls isBehavior]) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5839
            exClass := cls
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5840
        ] ifFalse:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5841
            exClass := Exception
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5842
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5843
        setOfTypes add:exClass.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5844
        ^ self
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5845
    ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5846
    ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5847
!
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5848
5606
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  5849
addClassesOfExpression:expr inClass:classOrNil to:setOfPossibleClasses
5803
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  5850
    |cls exprVal varName constraints|
5606
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  5851
5980
0ae8756ef72f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5973
diff changeset
  5852
    classResolverHook notNil ifTrue:[
0ae8756ef72f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5973
diff changeset
  5853
        setOfPossibleClasses addAll:((classResolverHook value:expr) ? #())
0ae8756ef72f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5973
diff changeset
  5854
    ].
0ae8756ef72f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5973
diff changeset
  5855
5606
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  5856
    (expr isVariable "and:[expr name = 'secondsOrNil']") ifTrue:[
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  5857
        "/ see if contained inside an isXXX ifTrue;
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  5858
        "/ then, we know a lot more...
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  5859
        expr parent notNil ifTrue:[
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  5860
            constraints := self extractConstraintsFor:expr inClass:classOrNil.
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  5861
            constraints notEmpty ifTrue:[
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  5862
                setOfPossibleClasses addAll:constraints.
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  5863
                ^ setOfPossibleClasses.    
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  5864
            ].    
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  5865
        ].
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  5866
    ].
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  5867
    
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5868
    expr isLiteral ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5869
        exprVal := expr value.
5502
427cef61298f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 5501
diff changeset
  5870
        cls := exprVal class.         
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5871
        (exprVal isArray or:[ exprVal isByteArray or:[ exprVal isString ]]) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5872
            exprVal isImmutable ifTrue:[
5606
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  5873
                setOfPossibleClasses add:cls mutableClass.
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  5874
                ^ setOfPossibleClasses.    
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5875
            ]
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5876
        ].
5606
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  5877
        setOfPossibleClasses add:cls. 
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  5878
        ^ setOfPossibleClasses.    
5502
427cef61298f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 5501
diff changeset
  5879
    ].
427cef61298f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 5501
diff changeset
  5880
    
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5881
    expr isBlock ifTrue:[
5606
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  5882
        setOfPossibleClasses add:Block. 
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  5883
        ^ setOfPossibleClasses.
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5884
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5885
5453
4e5f952f555d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5451
diff changeset
  5886
    thisContext isRecursive ifTrue:[
4e5f952f555d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5451
diff changeset
  5887
        |count|
4e5f952f555d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5451
diff changeset
  5888
        count := 0.
4e5f952f555d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5451
diff changeset
  5889
        thisContext withAllSendersDo:[:c | (c selector == thisContext selector) ifTrue:[count := count + 1 ]].
4e5f952f555d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5451
diff changeset
  5890
        count > 10 ifTrue:[
5606
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  5891
            ^ setOfPossibleClasses
5453
4e5f952f555d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5451
diff changeset
  5892
        ].
4e5f952f555d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5451
diff changeset
  5893
    ].
5131
832766a9972f #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5125
diff changeset
  5894
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5895
    expr isVariable ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5896
        varName := expr name.
5803
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  5897
        self addClassesOfVariable:varName inExpression:expr inClass:classOrNil to:setOfPossibleClasses.
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  5898
        ^ setOfPossibleClasses
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  5899
    ].
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  5900
    "/ we might get a degenerated / incomplete expression;
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  5901
    "/ especially in a workspace, where a variable is interpreted
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  5902
    "/ as a selector (when a period is missing before)
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  5903
    expr isMessage ifTrue:[
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  5904
        expr selector isUnarySelector ifTrue:[
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  5905
            varName := expr selector.
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  5906
            self addClassesOfVariable:varName inExpression:expr inClass:classOrNil to:setOfPossibleClasses.
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5907
        ].
5803
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  5908
    ].
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  5909
    
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5910
    (exprVal := self valueOfNode:expr) notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5911
        "/ knowing the value is always great!!
5606
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  5912
        setOfPossibleClasses add:exprVal class.
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  5913
        ^ setOfPossibleClasses.
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5914
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5915
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5916
    expr isMessage ifTrue:[
5606
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  5917
        self addClassesOfMessage:expr inClass:classOrNil to:setOfPossibleClasses.
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  5918
        ^ setOfPossibleClasses
5502
427cef61298f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 5501
diff changeset
  5919
    ].    
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5920
5606
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  5921
    ^ setOfPossibleClasses
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  5922
5502
427cef61298f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 5501
diff changeset
  5923
    "Modified: / 24-02-2017 / 14:41:00 / stefan"
5606
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  5924
    "Modified: / 15-09-2017 / 10:52:40 / cg"
5980
0ae8756ef72f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5973
diff changeset
  5925
    "Modified: / 27-12-2018 / 12:16:28 / Claus Gittinger"
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5926
!
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5927
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5928
addClassesOfInstVarNamed:varName inClass:aClass to:setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5929
    |instIndex type|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5930
    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5931
    instIndex := aClass instVarIndexFor:varName.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5932
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5933
    "/ ask the class
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5934
    (type := aClass typeOfInstVarNamed:varName) notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5935
        type isCollection ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5936
            setOfTypes addAll:type.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5937
        ] ifFalse:[    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5938
            setOfTypes add:type.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5939
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5940
        ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5941
    ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5942
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5943
    "/ look for instances
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5944
    aClass allSubInstancesDo:[:i |
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5945
        |varClass|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5946
        varClass := (i instVarAt:instIndex) class.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5947
        setOfTypes add:varClass.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5948
    ].  
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5949
    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5950
    "/ look for assignments in code
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5951
    aClass withAllSubclassesDo:[:eachClass |
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5952
        eachClass methodDictionary do:[:m |
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5953
            |tree code visitor|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5954
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5955
            "/ quick check
5125
63cf17a5b720 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5123
diff changeset
  5956
            SourceCodeManagerError handle:[:ex |
63cf17a5b720 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5123
diff changeset
  5957
            ] do:[    
63cf17a5b720 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5123
diff changeset
  5958
                code := m source.
63cf17a5b720 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 5123
diff changeset
  5959
            ].
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5960
            (code notNil and:[code includesString:varName]) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5961
                tree := Parser parse:code class:eachClass.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5962
                (tree notNil and:[tree ~~ #Error]) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5963
                    visitor := PluggableParseNodeVisitor new. 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5964
                    visitor 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5965
                        actionForNodeClass:AssignmentNode 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5966
                        put:[:node |
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5967
                            |val expr exprSelector|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5968
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5969
                            node variable name = varName ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5970
                                expr := node expression.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5971
                                "/ only look for wellknown types on the right side.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5972
                                expr isLiteral ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5973
                                    val := expr evaluate.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5974
                                    val isArray ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5975
                                        setOfTypes add:Array 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5976
                                    ] ifFalse:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5977
                                        setOfTypes add:val class
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5978
                                    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5979
                                ] ifFalse:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5980
                                    expr isMessage ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5981
                                        exprSelector := expr selector. 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5982
                                        ( #(+ - * /) includes:exprSelector ) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5983
                                            setOfTypes add:Number
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5984
                                        ] ifFalse:[    
5621
bc187db92ab4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5613
diff changeset
  5985
                                            ( #(// size basicSize position) includes:exprSelector ) ifTrue:[
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5986
                                                setOfTypes add:Integer
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5987
                                            ] ifFalse:[    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5988
                                                ( #(copy shallowCopy) includes:exprSelector ) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5989
                                                ] ifFalse:[    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5990
                                                    ( #(new new: basicNew basicNew:) includes:exprSelector ) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5991
                                                        expr receiver isGlobal ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5992
                                                            setOfTypes add:expr receiver evaluate
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5993
                                                        ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5994
                                                    ] ifFalse:[    
5660
295016846707 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 5658
diff changeset
  5995
                                                        self breakPoint:#DWIM.
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5996
                                                    ]
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5997
                                                ]
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5998
                                            ]
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  5999
                                        ]
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6000
                                    ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6001
                                ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6002
                            ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6003
                            true "/ yes - visit subnodes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6004
                        ].        
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6005
                    visitor visit:tree.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6006
                ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6007
            ]    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6008
        ]
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6009
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6010
    ^ setOfTypes
5621
bc187db92ab4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5613
diff changeset
  6011
bc187db92ab4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5613
diff changeset
  6012
    "Modified: / 11-10-2017 / 13:58:36 / cg"
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6013
!
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6014
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6015
addClassesOfMessage:expr inClass:classOrNil to:setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6016
    |valClass
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6017
     msgSelector msgReceiver msgArg1
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6018
     receiverClasses receiverClass 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6019
     arg1Classes arg1Value mthd|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6020
    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6021
    msgSelector := expr selector.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6022
         
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6023
    "/ heuristic: quickly assume boolean for some:
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6024
    (
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6025
        #( 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6026
            isNil notNil isEmpty isEmptyOrNil notEmpty notEmptyOrNil
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6027
            > >= < <= = == ~ ~=
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6028
            knownAsSymbol
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6029
            isMeta 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6030
            includes: contains:
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6031
            not and: or:
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6032
            exists atEnd positive negative odd even
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6033
        ) includes:msgSelector
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6034
    ) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6035
        setOfTypes add:True.  "/ use True, because Boolean does not include the full protocol
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6036
        ^ setOfTypes    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6037
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6038
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6039
    msgReceiver := expr receiver.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6040
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6041
    "/ some hardwired knowledge here
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6042
    receiverClasses := self classesOfNode:msgReceiver.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6043
    receiverClass := receiverClasses size == 1 ifTrue:[receiverClasses anElement] ifFalse:[nil].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6044
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6045
    receiverClass notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6046
        "/ follow Smalltalk at: to see what is there
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6047
        receiverClass == Smalltalk ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6048
            msgSelector == #at: ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6049
                msgArg1 := expr arg1.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6050
                msgArg1 isLiteralSymbol ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6051
                    arg1Value := Smalltalk at:msgArg1 value.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6052
                    arg1Value notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6053
                        setOfTypes add:arg1Value class.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6054
                        ^ setOfTypes.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6055
                    ]
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6056
                ]    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6057
            ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6058
        ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6059
        
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6060
        "/ usually return something of the receiver's type
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6061
        ( #(copy shallowCopy copyWith: , ) includes:msgSelector ) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6062
            setOfTypes addAll:receiverClasses.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6063
            ^ setOfTypes.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6064
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6065
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6066
        ( msgSelector == #class ) ifTrue:[  
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6067
            setOfTypes add:(receiverClass class).
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6068
            ^ setOfTypes            
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6069
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6070
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6071
        receiverClass isBehavior ifTrue:[                        
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6072
            ( #(compiledMethodAt:) includes:msgSelector) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6073
                setOfTypes add:Method.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6074
                ^ setOfTypes            
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6075
            ].            
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6076
            ( #(superclass) includes:msgSelector) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6077
                receiverClass isMeta ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6078
                    setOfTypes add:Metaclass.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6079
                ] ifFalse:[    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6080
                    setOfTypes add:Class.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6081
                ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6082
                ^ setOfTypes            
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6083
            ].            
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6084
            ( #(theNonMetaclass theMetaclass) includes:msgSelector) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6085
                receiverClass isMeta ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6086
                    setOfTypes add:Metaclass.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6087
                    ^ setOfTypes            
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6088
                ].
5462
6a7b577cd2b9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5453
diff changeset
  6089
                setOfTypes add:(receiverClass perform:msgSelector asSymbol) class.
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6090
                ^ setOfTypes            
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6091
            ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6092
            
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6093
            mthd := receiverClass lookupMethodFor:msgSelector.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6094
            receiverClass isMeta ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6095
                ( #( #'new' #'basicNew' #'new:' #'basicNew:' #'with:' #'with:with:') includes: msgSelector ) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6096
                    setOfTypes add:receiverClass theNonMetaclass.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6097
                    ^ setOfTypes.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6098
                ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6099
                "/ if that method sends one of new/basicNew/new:/basicNew:, assume it returns an instance of itself
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6100
                mthd notNil ifTrue:[
5451
32ed77c9d198 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  6101
                    ( mthd sendsAnySelector:#( #'new' #'basicNew' #'new:' #'basicNew:' )) ifTrue:[
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6102
                        setOfTypes add:receiverClass theNonMetaclass.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6103
                        ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6104
                    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6105
                ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6106
            ] ifFalse:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6107
                mthd notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6108
                    (ParseTreeSearcher methodIsSetterMethod:mthd) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6109
                        setOfTypes add:receiverClass.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6110
                        ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6111
                    ]
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6112
                ]
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6113
            ]
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6114
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6115
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6116
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6117
    ((msgSelector startsWith:'as')
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6118
    and:[ (valClass := Smalltalk classNamed:(msgSelector copyFrom:3)) notNil ]
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6119
    ) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6120
        setOfTypes add:valClass.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6121
        ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6122
    ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6123
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6124
    ((msgSelector startsWith:'is')
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6125
    and:[ (valClass := Smalltalk classNamed:(msgSelector copyFrom:3)) notNil ]
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6126
    ) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6127
        setOfTypes add:True. "/ True - not boolean; it does not contain the full protocol (would not find ifTrue:)
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6128
        ^ setOfTypes.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6129
    ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6130
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6131
    #(
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6132
        size                    SmallInteger
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6133
        hash                    SmallInteger
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6134
        identityHash            SmallInteger
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6135
        class                   Class
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6136
        theMetaclass            Metaclass
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6137
        theNonMetaclass         Class
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6138
        fork                    Process
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6139
        newProcess              Process
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6140
    ) pairWiseDo:[:sel :clsName |
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6141
        msgSelector == sel ifTrue:[ 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6142
            setOfTypes add:(Smalltalk at:clsName).
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6143
            ^ setOfTypes.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6144
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6145
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6146
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6147
    ( #( bitAnd: bitOr: bitShift: rightShift: >> << highBit lowBit ) includes:msgSelector) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6148
        "/ assume integer
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6149
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6150
        setOfTypes add:Integer.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6151
        ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6152
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6153
    ( #( + - * // \\ ) includes:msgSelector) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6154
        "/ assume numeric
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6155
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6156
        setOfTypes add:Number.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6157
        ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6158
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6159
    msgSelector == #/ ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6160
        ((receiverClasses ? #()) contains:[:cls | cls includesBehavior:Number]) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6161
            setOfTypes add:Number.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6162
            ^ setOfTypes.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6163
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6164
        msgArg1 := expr arguments at:1 ifAbsent:nil.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6165
        msgArg1 isNil ifTrue:[^ setOfTypes].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6166
        arg1Classes := ((self classesOfNode:msgArg1) ? #()).
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6167
        (arg1Classes contains:[:cls | cls includesBehavior:Number]) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6168
            setOfTypes add:Number.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6169
            ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6170
        ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6171
    ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6172
    ( #( construct: / ) includes:msgSelector) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6173
        ((receiverClasses ? #()) contains:[:cls | cls includesBehavior:Filename]) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6174
            setOfTypes add:Filename.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6175
            ^ setOfTypes
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6176
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6177
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6178
    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6179
    ^ setOfTypes
5451
32ed77c9d198 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  6180
5462
6a7b577cd2b9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5453
diff changeset
  6181
    "Modified: / 10-02-2017 / 10:39:41 / cg"
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6182
!
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6183
5803
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6184
addClassesOfVariable:varName inExpression:expr inClass:classOrNil to:setOfPossibleClasses
5804
aa470687012f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5803
diff changeset
  6185
    "expr is either a variable-node or a message in which varName is the selector"
aa470687012f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5803
diff changeset
  6186
    
5803
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6187
    |varScope instVarClass classVarClass privateClass poolVarClass 
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6188
     sym topNameSpace exprVal|
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6189
    
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6190
    varName = 'self' ifTrue:[
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6191
        instanceOrNil notNil ifTrue:[
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6192
            setOfPossibleClasses add:(instanceOrNil class).
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6193
        ] ifFalse:[    
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6194
            setOfPossibleClasses add:(classOrNil ? UndefinedObject).
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6195
        ].
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6196
        ^ setOfPossibleClasses
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6197
    ].
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6198
    varName = 'super' ifTrue:[
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6199
        classOrNil isNil 
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6200
            ifTrue:[setOfPossibleClasses add:Object]
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6201
            ifFalse:[setOfPossibleClasses add:classOrNil superclass].
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6202
        ^ setOfPossibleClasses.    
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6203
    ].
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6204
    varName = 'thisContext' ifTrue:[
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6205
        setOfPossibleClasses add:Context.
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6206
        ^ setOfPossibleClasses
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6207
    ].
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6208
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6209
    varScope := expr whoDefines: varName.
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6210
    (varScope notNil) ifTrue:[
5804
aa470687012f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5803
diff changeset
  6211
        expr isVariable ifTrue:[
aa470687012f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5803
diff changeset
  6212
            varScope isSequence ifTrue:[
aa470687012f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5803
diff changeset
  6213
                varScope := varScope parent.
aa470687012f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5803
diff changeset
  6214
            ].
aa470687012f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5803
diff changeset
  6215
aa470687012f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5803
diff changeset
  6216
            (varScope isBlock) ifTrue:[
aa470687012f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5803
diff changeset
  6217
                self addClassesOfBlockVarForWellknownBlocks:expr inScope:varScope to:setOfPossibleClasses.
aa470687012f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5803
diff changeset
  6218
                self addClassesFromAssignmentTo:varName in:varScope to:setOfPossibleClasses.
aa470687012f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5803
diff changeset
  6219
                self addClassesFromMessagesSentTo:expr in:varScope to:setOfPossibleClasses.
aa470687012f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5803
diff changeset
  6220
                ^ setOfPossibleClasses
aa470687012f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5803
diff changeset
  6221
            ].    
aa470687012f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5803
diff changeset
  6222
            (varScope isMethod) ifTrue:[
aa470687012f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5803
diff changeset
  6223
                self addClassesFromAssignmentTo:varName in:varScope to:setOfPossibleClasses.
aa470687012f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5803
diff changeset
  6224
                self addClassesFromMessagesSentTo:expr in:varScope to:setOfPossibleClasses.
aa470687012f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5803
diff changeset
  6225
                ^ setOfPossibleClasses
aa470687012f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5803
diff changeset
  6226
            ].    
5803
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6227
        ].
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6228
    ].
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6229
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6230
    classOrNil notNil ifTrue:[
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6231
        "/ inst var
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6232
        instVarClass := classOrNil whichClassDefinesInstVar:varName.
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6233
        instVarClass notNil ifTrue:[
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6234
            setOfPossibleClasses addAll:(self classesOfInstVarNamed:varName inClass:instVarClass).
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6235
            ^ setOfPossibleClasses
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6236
        ].    
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6237
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6238
        "/ class vars
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6239
        classVarClass := classOrNil theNonMetaclass whichClassDefinesClassVar:varName.
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6240
        classVarClass notNil ifTrue:[
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6241
            "/ see what is currently there
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6242
            setOfPossibleClasses add:(classVarClass classVarAt:varName asSymbol) class.
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6243
            ^ setOfPossibleClasses
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6244
        ].    
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6245
        varName isUppercaseFirst ifTrue:[
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6246
            "/ private class
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6247
            varName knownAsSymbol ifTrue:[
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6248
                privateClass := classOrNil theNonMetaclass privateClassesAt:varName asSymbol.
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6249
                privateClass notNil ifTrue:[
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6250
                    setOfPossibleClasses add:(privateClass theMetaclass).
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6251
                    ^ setOfPossibleClasses
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6252
                ].    
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6253
            ].    
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6254
        ].
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6255
        "/ pool vars
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6256
        poolVarClass := classOrNil theNonMetaclass whichPoolDefinesPoolVar:varName.
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6257
        poolVarClass notNil ifTrue:[
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6258
            "/ see what is currently there
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6259
            setOfPossibleClasses add:(poolVarClass classVarAt:varName asSymbol) class.
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6260
            ^ setOfPossibleClasses
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6261
        ].    
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6262
    ].
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6263
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6264
    varName isUppercaseFirst ifTrue:[
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6265
        sym := varName asSymbolIfInterned.
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6266
        sym notNil ifTrue:[
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6267
            (classOrNil isNil or:[(topNameSpace := classOrNil topNameSpace) isNil]) ifTrue:[
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6268
                topNameSpace := Smalltalk.
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6269
            ].
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6270
            exprVal := topNameSpace at:sym.
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6271
            exprVal notNil ifTrue:[
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6272
                setOfPossibleClasses add:(exprVal class).
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6273
            ].
6036
171e12f06b70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6022
diff changeset
  6274
            topNameSpace ~~ Smalltalk ifTrue:[
171e12f06b70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6022
diff changeset
  6275
                exprVal := Smalltalk at:sym.
171e12f06b70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6022
diff changeset
  6276
                exprVal notNil ifTrue:[
171e12f06b70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6022
diff changeset
  6277
                    setOfPossibleClasses add:(exprVal class).
171e12f06b70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6022
diff changeset
  6278
                ].
171e12f06b70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6022
diff changeset
  6279
            ].
5803
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6280
        ].        
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6281
    ].    
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6282
    ^ setOfPossibleClasses
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6283
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6284
    "Created: / 13-06-2018 / 10:17:42 / Claus Gittinger"
6036
171e12f06b70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 6022
diff changeset
  6285
    "Modified: / 18-03-2019 / 11:28:39 / Claus Gittinger"
5803
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6286
!
c46ed8974a7c #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5784
diff changeset
  6287
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6288
classOfNode:aNode
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6289
    "returns the class of a receiver, if it is well-known.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6290
     Otherwise nil (either unknown, or multiple possibilities)
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6291
     When showing possible completions for a message,
5621
bc187db92ab4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5613
diff changeset
  6292
     it is a good idea to know what the receiver is."
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6293
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6294
    | classes |
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6295
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6296
    classes := self classesOfNode:aNode.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6297
    classes size == 1 ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6298
        ^ classes anElement
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6299
    ].
5621
bc187db92ab4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5613
diff changeset
  6300
    "/ self breakPoint:#cg.
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6301
    ^ nil
5621
bc187db92ab4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5613
diff changeset
  6302
bc187db92ab4 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5613
diff changeset
  6303
    "Modified: / 10-10-2017 / 16:56:43 / cg"
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6304
!
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6305
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6306
classesFromAssignmentTo:varName in:aTree
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6307
    ^ self addClassesFromAssignmentTo:varName in:aTree to:IdentitySet new
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6308
!
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6309
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6310
classesOfInstVarNamed:varName inClass:aClass
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6311
    ^ self addClassesOfInstVarNamed:varName inClass:aClass to:(IdentitySet new)
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6312
!
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6313
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6314
classesOfNode:aNode
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6315
    "returns the set of possible classes of a parsenode.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6316
     or nil if unknown.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6317
     When showing possible completions for a message,
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6318
     it is a good idea to know what the kind receiver is."
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6319
5606
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6320
    |setOfPossibleClasses|
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6321
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6322
    setOfPossibleClasses := IdentitySet new.
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6323
    self addClassesOfExpression:aNode inClass:classOrNil to:setOfPossibleClasses.
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6324
    ^ setOfPossibleClasses.
5453
4e5f952f555d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5451
diff changeset
  6325
4e5f952f555d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5451
diff changeset
  6326
    "Modified: / 05-02-2017 / 12:40:16 / cg"
5606
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6327
    "Modified (format): / 15-09-2017 / 10:11:19 / cg"
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6328
!
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6329
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6330
extractConstraintsFor:expr inClass:dummyClassOrNil
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6331
    "see if expr is contained inside an isXXX ifTrue:[...]
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6332
     then, we know a lot more...
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6333
     For example, to expand possible messages for XXX in:
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6334
        foo isString ifTrue:[
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6335
            f XXX
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6336
        ].
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6337
     we now have to care for instances for which isString returns true only"   
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6338
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6339
    |node parentNode possibleClasses allImplementors condition classesReturningTrue classesReturningFalse|
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6340
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6341
    possibleClasses := Set new.
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6342
    
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6343
    node := expr.
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6344
    [
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6345
        parentNode := node parent.
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6346
        parentNode isNil ifTrue:[
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6347
            "/ due to the partial parse (being right in the middle of a parse),
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6348
            "/ the parent may be undefined (for example, if closing bracket of a block was not yet entered)
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6349
            "/ then the parse stopped and we have the partial parent message in the rememberedNodes list.
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6350
            "/ try there; if found, continue there. If not, well, we might be really at the top.
5608
585c8f740aea #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5607
diff changeset
  6351
            rememberedNodes notNil ifTrue:[
585c8f740aea #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5607
diff changeset
  6352
                rememberedNodes do:[:eachPossibleParentNode |
5609
8a30b1f720d7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5608
diff changeset
  6353
                    (eachPossibleParentNode stop notNil and:[ node start notNil ]) ifTrue:[
5608
585c8f740aea #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5607
diff changeset
  6354
                        eachPossibleParentNode stop <= node start ifTrue:[
585c8f740aea #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5607
diff changeset
  6355
                            (parentNode isNil or:[parentNode stop < eachPossibleParentNode stop]) ifTrue:[
585c8f740aea #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5607
diff changeset
  6356
                                parentNode := eachPossibleParentNode
585c8f740aea #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5607
diff changeset
  6357
                            ].    
5606
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6358
                        ].    
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6359
                    ].    
5608
585c8f740aea #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5607
diff changeset
  6360
                ].
5612
e77a2fa2031f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5609
diff changeset
  6361
                parentNode notNil ifTrue:[ rememberedNodes removeIdentical:parentNode ].
5606
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6362
            ].
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6363
        ].    
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6364
        parentNode notNil
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6365
    ] whileTrue:[
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6366
        (parentNode isMessage 
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6367
            and:[#(ifTrue:) includes:parentNode selector])
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6368
        ifTrue:[ 
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6369
            (condition := parentNode receiver) isMessage ifTrue:[
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6370
                condition receiver isVariable ifTrue:[
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6371
                    condition receiver name = expr name ifTrue:[
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6372
                        "/ here, we have an if, sending some message to the same receiver variable
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6373
                        allImplementors := Smalltalk allImplementorsOf:condition selector.
5633
f888f84e67f7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5621
diff changeset
  6374
                        SourceCodeManagerError handle:[:ex |
f888f84e67f7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5621
diff changeset
  6375
                        ] do:[
f888f84e67f7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5621
diff changeset
  6376
                            classesReturningTrue := 
f888f84e67f7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5621
diff changeset
  6377
                                allImplementors select:[:cls | 
f888f84e67f7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5621
diff changeset
  6378
                                                    |mthd|
f888f84e67f7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5621
diff changeset
  6379
f888f84e67f7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5621
diff changeset
  6380
                                                    mthd := cls compiledMethodAt:condition selector.
f888f84e67f7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5621
diff changeset
  6381
                                                    ParseTreeSearcher methodIsJustReturningTrue:mthd.
f888f84e67f7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5621
diff changeset
  6382
                                                ].
f888f84e67f7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5621
diff changeset
  6383
f888f84e67f7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5621
diff changeset
  6384
                            classesReturningTrue do:[:eachClass |
f888f84e67f7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5621
diff changeset
  6385
                                eachClass withAllSubclassesDo:[:eachSubClass |
f888f84e67f7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5621
diff changeset
  6386
                                    possibleClasses add:eachSubClass
f888f84e67f7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5621
diff changeset
  6387
                                ].
5606
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6388
                            ].
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6389
                        ].
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6390
                        ^ possibleClasses.
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6391
                    ].        
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6392
                ].        
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6393
            ].    
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6394
        ].
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6395
        node := parentNode.
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6396
    ].    
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6397
    ^ possibleClasses
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6398
28585ddb3a51 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  6399
    "Created: / 15-09-2017 / 10:16:20 / cg"
5633
f888f84e67f7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5621
diff changeset
  6400
    "Modified: / 05-11-2017 / 02:59:59 / cg"
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6401
!
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6402
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6403
isNonDestructive:aMessageNode whenSentTo:receiverValue
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6404
    "return true, if it is safe to send aSelector to receiverValue
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6405
     (i.e. has no side effects)"
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6406
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6407
    |selector method impl arg1Value|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6408
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6409
    selector := aMessageNode selector.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6410
    impl := receiverValue class whichClassIncludesSelector:selector.
5706
6aa652210ae2 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
  6411
    impl isNil ifTrue:[
6aa652210ae2 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
  6412
        ^ false "/ don't know - but assume it is dangerous
6aa652210ae2 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
  6413
    ].
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6414
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6415
    ( #( 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6416
        basicSize basicAt:
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6417
        class theMetaclass theNonMetaclass ) includes:selector
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6418
    ) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6419
        ^ true.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6420
    ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6421
    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6422
    selector == #size ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6423
        "/ mhm - be conservative; someone might have redefined #size
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6424
        "/ more hardwired stuff.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6425
        ((impl == Object) or:[(impl == String) or:[impl isSubclassOf:Collection]]) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6426
            ^ true.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6427
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6428
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6429
    selector == #at: ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6430
        "/ mhm - be conservative; someone might have redefined #at: and do something there
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6431
        "/ more hardwired stuff.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6432
        arg1Value := self valueOfNode:(aMessageNode arg1).
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6433
        arg1Value notNil ifTrue:[            
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6434
            receiverValue == Smalltalk ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6435
                ^ arg1Value isSymbol
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6436
            ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6437
        
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6438
            ((impl == Object) or:[(impl == String) or:[(impl isSubclassOf:Collection)]]) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6439
                ^ true.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6440
            ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6441
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6442
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6443
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6444
    selector argumentCount == 0 ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6445
        "/ follow non-destructive accessors
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6446
        method := receiverValue class lookupMethodFor:selector.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6447
        method notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6448
            (ParseTreeSearcher methodIsJustReturningSomething:method) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6449
                "/ we can savely call that method to get the current value
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6450
                ^ true.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6451
            ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6452
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6453
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6454
    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6455
    ^ false
5512
4375d3732703 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5509
diff changeset
  6456
4375d3732703 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5509
diff changeset
  6457
    "Modified: / 09-03-2017 / 10:58:50 / cg"
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6458
!
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6459
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6460
valueAndKindOfVariable:aVariableName
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6461
    "when showing possible completions for a variable,
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6462
     it is a good idea to know what the reveiver's value is.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6463
     Sigh - returns nil as value both if unknown AND if a real nil is there"
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6464
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6465
    |nodeVal con classInstVarClass classVarClass privateClass pool sym nameSpace topNameSpace|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6466
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6467
    aVariableName isUppercaseFirst ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6468
        classOrNil notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6469
            classOrNil isMeta ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6470
                "/ class instVars
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6471
                (classInstVarClass := classOrNil whichClassDefinesInstVar:aVariableName) notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6472
                    nodeVal := classInstVarClass theNonMetaclass instVarNamed:aVariableName.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6473
                    ^ { nodeVal . #classInstVariable }
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6474
                ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6475
            ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6476
            "/ class vars
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6477
            (classVarClass := classOrNil theNonMetaclass whichClassDefinesClassVar:aVariableName) notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6478
                nodeVal := classVarClass classVarAt:aVariableName asSymbol.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6479
                ^ { nodeVal . #classVariable }
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6480
            ].    
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6481
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6482
            privateClass := classOrNil theNonMetaclass privateClasses detect:[:cls | cls nameWithoutPrefix = aVariableName] ifNone:nil.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6483
            privateClass notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6484
                nodeVal := privateClass.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6485
                ^ { nodeVal . #privateClass }
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6486
            ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6487
            pool := classOrNil theNonMetaclass whichPoolDefinesPoolVar:aVariableName.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6488
            pool notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6489
                nodeVal := pool classVarAt:aVariableName.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6490
                ^ { nodeVal . #poolVariable }
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6491
            ].
5118
69c5afaa4ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5114
diff changeset
  6492
            (sym := aVariableName asSymbolIfInterned) notNil ifTrue:[
69c5afaa4ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5114
diff changeset
  6493
                ((nameSpace := classOrNil nameSpace) notNil and:[nameSpace ~~ Smalltalk]) ifTrue:[
69c5afaa4ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5114
diff changeset
  6494
                    nameSpace isNameSpace ifTrue:[
69c5afaa4ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5114
diff changeset
  6495
                        nodeVal := nameSpace at:sym.
69c5afaa4ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5114
diff changeset
  6496
                        (nodeVal notNil or:[nameSpace includesKey:sym]) ifTrue:[     
69c5afaa4ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5114
diff changeset
  6497
                            ^ { nodeVal . #nameSpaceVariable }
69c5afaa4ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5114
diff changeset
  6498
                        ].
69c5afaa4ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5114
diff changeset
  6499
                    ].
69c5afaa4ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5114
diff changeset
  6500
                    nodeVal := nameSpace privateClassNamed:sym.
69c5afaa4ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5114
diff changeset
  6501
                    (nodeVal notNil) ifTrue:[     
69c5afaa4ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5114
diff changeset
  6502
                        ^ { nodeVal . #privateClass }
69c5afaa4ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5114
diff changeset
  6503
                    ].    
69c5afaa4ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5114
diff changeset
  6504
                ].    
69c5afaa4ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5114
diff changeset
  6505
                ((topNameSpace := classOrNil topNameSpace) notNil 
69c5afaa4ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5114
diff changeset
  6506
                and:[topNameSpace ~~ nameSpace
69c5afaa4ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5114
diff changeset
  6507
                and:[topNameSpace ~~ Smalltalk]]) ifTrue:[
69c5afaa4ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5114
diff changeset
  6508
                    nodeVal := topNameSpace at:sym.
69c5afaa4ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5114
diff changeset
  6509
                    (nodeVal notNil or:[topNameSpace includesKey:sym]) ifTrue:[     
69c5afaa4ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5114
diff changeset
  6510
                        ^ { nodeVal . #nameSpaceVariable }
69c5afaa4ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5114
diff changeset
  6511
                    ].    
69c5afaa4ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5114
diff changeset
  6512
                ].    
69c5afaa4ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5114
diff changeset
  6513
            ].
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6514
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6515
        (sym := aVariableName asSymbolIfInterned) notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6516
            nodeVal := Smalltalk at:sym.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6517
            (nodeVal notNil or:[Smalltalk includesKey:sym]) ifTrue:[     
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6518
                ^ { nodeVal . #global }
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6519
            ]
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6520
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6521
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6522
        "/ 'evaluate' the variable (like in a browser's codeView)
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6523
        "/ mhmh - will we catch workspace vars then?
5118
69c5afaa4ddd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 5114
diff changeset
  6524
        Error ignoreIn:[
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6525
            nodeVal := Parser new evaluate:aVariableName in:classOrNil receiver:classOrNil.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6526
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6527
        nodeVal notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6528
            ^ { nodeVal . #global }
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6529
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6530
        ^ nil
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6531
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6532
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6533
    aVariableName = 'self' ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6534
        contextOrNil notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6535
            ^ { contextOrNil receiver . #pseudoVar } 
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6536
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6537
        (classOrNil notNil and:[classOrNil isMeta]) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6538
            "/ ^ { classOrNil . #pseudoVar }
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6539
            ^ { classOrNil theNonMetaclass . #pseudoVar }
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6540
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6541
        ^ nil
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6542
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6543
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6544
    contextOrNil notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6545
        "/ in the debugger, we know more
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6546
        con := contextOrNil.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6547
        [ con notNil ] whileTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6548
            "/ a local in the context?
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6549
            ((con argAndVarNames ? #()) includes:aVariableName) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6550
                nodeVal := con argsAndVars at:(con argAndVarNames indexOf:aVariableName) ifAbsent:nil.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6551
                nodeVal notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6552
                    ^ { nodeVal . #argument }
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6553
                ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6554
            ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6555
            con := con home.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6556
        ].
5370
ec87b8971f7b #BUGFIX by mawalch
mawalch
parents: 5368
diff changeset
  6557
        "/ an instvar?
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6558
        (contextOrNil receiver class allInstVarNames includes:aVariableName) ifTrue:[
5370
ec87b8971f7b #BUGFIX by mawalch
mawalch
parents: 5368
diff changeset
  6559
            contextOrNil receiver isProtoObject ifFalse:[
ec87b8971f7b #BUGFIX by mawalch
mawalch
parents: 5368
diff changeset
  6560
                nodeVal := contextOrNil receiver instVarNamed:aVariableName.
ec87b8971f7b #BUGFIX by mawalch
mawalch
parents: 5368
diff changeset
  6561
            ].
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6562
            nodeVal notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6563
                ^ { nodeVal . #instanceVariable }
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6564
            ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6565
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6566
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6567
    ^ nil
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6568
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6569
    "Created: / 01-05-2016 / 12:40:05 / cg"
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6570
!
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6571
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6572
valueOfNode:aNode
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6573
    "when showing possible completions for a message,
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6574
     it is a good idea to know what the reveiver's value is.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6575
     Sigh - returns nil both if unknown AND if a real nil is there."
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6576
5368
1b5ca0f20be5 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 5360
diff changeset
  6577
    |nodeSelector nodeReceiver receiverValue arg1Value|
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6578
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6579
    aNode isLiteral ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6580
        ^ aNode value
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6581
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6582
    aNode isVariable ifTrue:[
5512
4375d3732703 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5509
diff changeset
  6583
        aNode isSelf ifTrue:[
4375d3732703 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5509
diff changeset
  6584
            instanceOrNil notNil ifTrue:[
4375d3732703 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5509
diff changeset
  6585
                ^ instanceOrNil
4375d3732703 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5509
diff changeset
  6586
            ].    
4375d3732703 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5509
diff changeset
  6587
        ].    
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6588
        ^ self valueOfVariable:aNode name.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6589
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6590
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6591
    aNode isMessage ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6592
        nodeSelector := aNode selector.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6593
        nodeReceiver := aNode receiver.
5512
4375d3732703 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5509
diff changeset
  6594
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6595
        "/ some hardwired knowledge here
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6596
        classOrNil notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6597
            (nodeReceiver isSelf and:[nodeSelector = #'class']) ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6598
                ^ classOrNil
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6599
            ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6600
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6601
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6602
        receiverValue := self valueOfNode:nodeReceiver.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6603
        receiverValue notNil ifTrue:[
5368
1b5ca0f20be5 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 5360
diff changeset
  6604
            (self isNonDestructive:aNode whenSentTo:receiverValue) ifTrue:[
1b5ca0f20be5 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 5360
diff changeset
  6605
                [
1b5ca0f20be5 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 5360
diff changeset
  6606
                     nodeSelector argumentCount == 1 ifTrue:[
1b5ca0f20be5 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 5360
diff changeset
  6607
                        arg1Value := self valueOfNode:(aNode arg1).
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6608
                        ^ receiverValue perform: nodeSelector with: arg1Value.
5368
1b5ca0f20be5 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 5360
diff changeset
  6609
                    ].    
1b5ca0f20be5 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 5360
diff changeset
  6610
                    ^ receiverValue perform: nodeSelector.
1b5ca0f20be5 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 5360
diff changeset
  6611
                ] on:Error do:[
1b5ca0f20be5 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 5360
diff changeset
  6612
                    ^ nil
1b5ca0f20be5 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 5360
diff changeset
  6613
                ]    
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6614
            ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6615
        ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6616
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6617
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6618
    ^ nil
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6619
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6620
    "Created: / 28-08-2013 / 16:34:53 / cg"
5512
4375d3732703 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5509
diff changeset
  6621
    "Modified: / 09-03-2017 / 10:58:42 / cg"
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6622
!
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6623
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6624
valueOfVariable:aVariableName
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6625
    "when showing possible completions for a variable,
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6626
     it is a good idea to know what the reveiver's value is.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6627
     Sigh - returns nil both if unknown AND if a real nil is there."
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6628
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6629
    |valueAndKind|
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6630
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6631
    (valueAndKind := self valueAndKindOfVariable:aVariableName) notNil ifTrue:[
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6632
        self assert:valueAndKind isArray.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6633
        ^ valueAndKind first.
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6634
    ].
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6635
    ^ nil
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6636
5225
8bcca5a042c5 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 5224
diff changeset
  6637
    "Modified: / 26-08-2016 / 14:16:16 / cg"
5109
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6638
! !
18c01df208c2 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 5106
diff changeset
  6639
5980
0ae8756ef72f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5973
diff changeset
  6640
!DoWhatIMeanSupport methodsFor:'setup'!
0ae8756ef72f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5973
diff changeset
  6641
0ae8756ef72f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5973
diff changeset
  6642
classResolverHook:aBlock
0ae8756ef72f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5973
diff changeset
  6643
    "additional hook to allow for special class resolving.
0ae8756ef72f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5973
diff changeset
  6644
     If non-nil, this hook is called for expression nodes,
0ae8756ef72f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5973
diff changeset
  6645
     and may return a class or nil.
0ae8756ef72f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5973
diff changeset
  6646
     Used eg. with expecco to resolve pin types"
0ae8756ef72f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5973
diff changeset
  6647
0ae8756ef72f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5973
diff changeset
  6648
    classResolverHook := aBlock
0ae8756ef72f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5973
diff changeset
  6649
0ae8756ef72f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5973
diff changeset
  6650
    "
0ae8756ef72f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5973
diff changeset
  6651
     self new classResolverHook:[:expr |
0ae8756ef72f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5973
diff changeset
  6652
         (expr isVariable and:[expr name = 'foo']) ifTrue:[
0ae8756ef72f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5973
diff changeset
  6653
             { String }
0ae8756ef72f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5973
diff changeset
  6654
         ] ifFalse:[
0ae8756ef72f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5973
diff changeset
  6655
             nil
0ae8756ef72f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5973
diff changeset
  6656
         ]
0ae8756ef72f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5973
diff changeset
  6657
     ].
0ae8756ef72f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5973
diff changeset
  6658
     
0ae8756ef72f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5973
diff changeset
  6659
    "
0ae8756ef72f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5973
diff changeset
  6660
0ae8756ef72f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5973
diff changeset
  6661
    "Created: / 27-12-2018 / 12:11:31 / Claus Gittinger"
0ae8756ef72f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5973
diff changeset
  6662
! !
0ae8756ef72f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 5973
diff changeset
  6663
3854
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6664
!DoWhatIMeanSupport::InputCompletionResult class methodsFor:'instance creation'!
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6665
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6666
bestName:bestNameArg matchingNames:matchingNamesArg
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6667
    ^ self with:bestNameArg with:matchingNamesArg
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6668
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6669
    "
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6670
     self bestName:123 matchingNames:345
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6671
    "
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6672
! !
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6673
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6674
!DoWhatIMeanSupport::InputCompletionResult methodsFor:'accessing'!
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6675
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6676
bestName
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6677
    ^ self at:1
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6678
!
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6679
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6680
matchingNames
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6681
    ^ self at:2
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6682
! !
d7904ce12bb6 changed: #classnameCompletion:filter:inEnvironment:
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
  6683
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  6684
!DoWhatIMeanSupport class methodsFor:'documentation'!
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  6685
4281
05f2bc8ee7e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4280
diff changeset
  6686
version
4784
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  6687
    ^ '$Header$'
4281
05f2bc8ee7e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4280
diff changeset
  6688
!
05f2bc8ee7e4 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4280
diff changeset
  6689
3761
6584390d427d dont forget pool variables when looking for the best variable match
Claus Gittinger <cg@exept.de>
parents: 3751
diff changeset
  6690
version_CVS
4784
7c4d1f1a6b30 class: DoWhatIMeanSupport
Claus Gittinger <cg@exept.de>
parents: 4780
diff changeset
  6691
    ^ '$Header$'
2376
41e0228c4c58 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  6692
! !
4194
e677aae984be Refactoring:
Stefan Vogel <sv@exept.de>
parents: 4148
diff changeset
  6693