author | Claus Gittinger <cg@exept.de> |
Sat, 11 Oct 2008 19:02:40 +0200 | |
changeset 3552 | e631f2f7bb2a |
parent 3551 | 0c83710ae45e |
child 3554 | 96238651bc4c |
permissions | -rw-r--r-- |
2376 | 1 |
" |
2 |
COPYRIGHT (c) 2002 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
"{ Package: 'stx:libwidg2' }" |
|
13 |
||
14 |
Object subclass:#DoWhatIMeanSupport |
|
15 |
instanceVariableNames:'' |
|
3475
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
16 |
classVariableNames:'LastSource LastParseTree' |
2376 | 17 |
poolDictionaries:'' |
18 |
category:'System-Support' |
|
19 |
! |
|
20 |
||
21 |
!DoWhatIMeanSupport class methodsFor:'documentation'! |
|
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 2002 by eXept Software AG |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
37 |
documentation |
|
38 |
" |
|
39 |
misc collected UI support (functional) |
|
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
40 |
These used to be in the Smalltalk and SystemBrowser class; |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
41 |
however, they are only needed for programmers, and some of the stuff is useful in multiple |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
42 |
places. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
43 |
Therefore is is: |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
44 |
1) not needed for standalone executables |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
45 |
2) published here to avoid multiple implementations |
2376 | 46 |
|
47 |
[author:] |
|
48 |
Claus Gittinger (cg@exept.de) |
|
49 |
||
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
50 |
" |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
51 |
! ! |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
52 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
53 |
!DoWhatIMeanSupport class methodsFor:'code completion'! |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
54 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
55 |
codeCompletionForClass:cls codeView:codeView |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
56 |
|crsrPos char interval source node checkedNode| |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
57 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
58 |
cls isNil ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
59 |
self information:'No class'. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
60 |
^ self. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
61 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
62 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
63 |
interval := codeView selectedInterval. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
64 |
interval isEmpty ifTrue:[ |
3306
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
65 |
crsrPos := codeView characterPositionOfCursor-1. |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
66 |
char := codeView characterAtCharacterPosition:crsrPos. |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
67 |
|
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
68 |
[crsrPos > 1 and:[char isSeparator or:['.' includes:char]]] whileTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
69 |
crsrPos := crsrPos - 1. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
70 |
char := codeView characterAtCharacterPosition:crsrPos. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
71 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
72 |
interval := crsrPos to:crsrPos. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
73 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
74 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
75 |
source := codeView contentsAsString string. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
76 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
77 |
node := self findNodeForInterval:interval in:source allowErrors:true. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
78 |
[node isNil] whileTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
79 |
"/ expand to the left ... |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
80 |
interval start > 1 ifFalse:[ |
3306
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
81 |
crsrPos := codeView characterPositionOfCursor. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
82 |
self information:'No parseNode found'. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
83 |
^ self. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
84 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
85 |
interval start:(interval start - 1). |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
86 |
node := self findNodeForInterval:interval in:source allowErrors:true. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
87 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
88 |
|
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
89 |
(node isVariable |
3366 | 90 |
and:[ node parent notNil |
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
91 |
and:[ node parent isMessage |
3366 | 92 |
and:[ node stop < (codeView characterPositionOfCursor-1) ]]]) ifTrue:[ |
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
93 |
node := node parent. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
94 |
]. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
95 |
|
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
96 |
node isVariable ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
97 |
self codeCompletionForVariable:node inClass:cls codeView:codeView. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
98 |
^ self. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
99 |
]. |
3552
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
100 |
node isLiteral ifTrue:[ |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
101 |
node value isSymbol ifTrue:[ |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
102 |
self codeCompletionForLiteralSymbol:node inClass:cls codeView:codeView. |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
103 |
^ self. |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
104 |
]. |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
105 |
]. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
106 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
107 |
checkedNode := node. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
108 |
[checkedNode notNil] whileTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
109 |
checkedNode isMessage ifTrue:[ |
3306
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
110 |
"/ completion in a message-send |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
111 |
self codeCompletionForMessage:checkedNode inClass:cls codeView:codeView. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
112 |
^ self |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
113 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
114 |
checkedNode isMethod ifTrue:[ |
3306
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
115 |
"/ completion in a methods selector pattern |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
116 |
self codeCompletionForMethod:checkedNode inClass:cls codeView:codeView. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
117 |
^ self. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
118 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
119 |
checkedNode := checkedNode parent. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
120 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
121 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
122 |
self information:'Node is neither variable nor message.'. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
123 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
124 |
"Modified: / 04-07-2006 / 18:48:26 / fm" |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
125 |
"Modified: / 20-11-2006 / 12:30:59 / cg" |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
126 |
! ! |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
127 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
128 |
!DoWhatIMeanSupport class methodsFor:'code completion-helpers'! |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
129 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
130 |
askUserForCompletion:what for:codeView from:allTheBest |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
131 |
allTheBest isEmpty ifTrue:[ ^ nil ]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
132 |
allTheBest size == 1 ifTrue:[ ^ allTheBest first ]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
133 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
134 |
allTheBest size < 20 ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
135 |
|menu idx exitKey| |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
136 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
137 |
menu := PopUpMenu labels:allTheBest. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
138 |
menu hideOnKeyFilter:[:key | |hide| |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
139 |
hide := ( #( CursorDown CursorUp Escape Return ) includes: key) not. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
140 |
hide ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
141 |
exitKey := key. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
142 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
143 |
hide]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
144 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
145 |
idx := menu startUp. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
146 |
idx == 0 ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
147 |
exitKey notNil ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
148 |
codeView keyPress:exitKey x:0 y:0. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
149 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
150 |
^ nil |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
151 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
152 |
^ allTheBest at:idx. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
153 |
] ifFalse:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
154 |
^ Dialog |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
155 |
choose:(codeView application resources string:'Choose ',what) |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
156 |
fromList:allTheBest |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
157 |
lines:10 |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
158 |
title:(codeView application resources string:'Code completion'). |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
159 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
160 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
161 |
"Created: / 10-11-2006 / 14:00:53 / cg" |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
162 |
! |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
163 |
|
3552
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
164 |
codeCompletionForLiteralSymbol:node inClass:cls codeView:codeView |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
165 |
|sym possibleCompletions best start stop oldLen newLen oldVar| |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
166 |
|
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
167 |
sym := node value. |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
168 |
possibleCompletions := OrderedCollection new. |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
169 |
|
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
170 |
Symbol allInstancesDo:[:existingSym | |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
171 |
(existingSym startsWith:sym) ifTrue:[ |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
172 |
(existingSym = sym) ifFalse:[ |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
173 |
possibleCompletions add:existingSym |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
174 |
]. |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
175 |
]. |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
176 |
]. |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
177 |
possibleCompletions sort. |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
178 |
|
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
179 |
best := possibleCompletions longestCommonPrefix. |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
180 |
(best = sym or:[(possibleCompletions includes:best) not]) ifTrue:[ |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
181 |
best := self askUserForCompletion:'symbol literal' for:codeView from:possibleCompletions. |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
182 |
best isNil ifTrue:[^ self]. |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
183 |
]. |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
184 |
|
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
185 |
"/ self showInfo:best. |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
186 |
|
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
187 |
start := node start. |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
188 |
stop := node stop. |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
189 |
(codeView characterAtCharacterPosition:start) == $# ifTrue:[ |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
190 |
start := start + 1. |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
191 |
]. |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
192 |
(codeView characterAtCharacterPosition:start) == $' ifTrue:[ |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
193 |
start := start + 1. |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
194 |
stop := stop - 1. |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
195 |
]. |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
196 |
|
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
197 |
oldVar := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators. |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
198 |
|
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
199 |
codeView |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
200 |
undoableDo:[ codeView replaceFromCharacterPosition:start to:stop with:best ] |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
201 |
info:'completion'. |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
202 |
|
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
203 |
(best startsWith:oldVar) ifTrue:[ |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
204 |
oldLen := stop - start + 1. |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
205 |
newLen := best size. |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
206 |
codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1. |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
207 |
codeView dontReplaceSelectionOnInput |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
208 |
]. |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
209 |
! |
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
210 |
|
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
211 |
codeCompletionForMessage:node inClass:cls codeView:codeView |
3545
1cbb9b58d37a
better message-selector completion
Claus Gittinger <cg@exept.de>
parents:
3543
diff
changeset
|
212 |
|selector srchClass implClass |
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
213 |
bestSelectors selector2 bestSelectors2 allBest best info numArgs |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
214 |
newParts nSelParts oldLen newLen selectorParts |
3545
1cbb9b58d37a
better message-selector completion
Claus Gittinger <cg@exept.de>
parents:
3543
diff
changeset
|
215 |
findBest parentNode selectorInBest selector2InBest2 |
1cbb9b58d37a
better message-selector completion
Claus Gittinger <cg@exept.de>
parents:
3543
diff
changeset
|
216 |
parser selectorsSentInCode allBest1 allBest2| |
1cbb9b58d37a
better message-selector completion
Claus Gittinger <cg@exept.de>
parents:
3543
diff
changeset
|
217 |
|
1cbb9b58d37a
better message-selector completion
Claus Gittinger <cg@exept.de>
parents:
3543
diff
changeset
|
218 |
parser := Parser parseMethod:codeView contents string in:cls ignoreErrors:true ignoreWarnings:true. |
1cbb9b58d37a
better message-selector completion
Claus Gittinger <cg@exept.de>
parents:
3543
diff
changeset
|
219 |
selectorsSentInCode := parser messagesSent. |
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
220 |
|
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
221 |
findBest := [:node :selector | |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
222 |
|srchClass bestSelectors bestPrefixes| |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
223 |
|
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
224 |
srchClass := self lookupClassForMessage:node inClass:cls. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
225 |
|
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
226 |
srchClass notNil ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
227 |
bestSelectors := Parser findBestSelectorsFor:selector in:srchClass. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
228 |
] ifFalse:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
229 |
codeView topView withCursor:(Cursor questionMark) do:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
230 |
bestSelectors := Parser findBestSelectorsFor:selector. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
231 |
]. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
232 |
]. |
2376 | 233 |
|
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
234 |
(bestSelectors includes:selector) ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
235 |
bestSelectors := bestSelectors select:[:sel | sel size > selector size]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
236 |
]. |
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
237 |
bestPrefixes := bestSelectors select:[:sel | sel asLowercase startsWith:selector asLowercase]. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
238 |
bestPrefixes size > 0 ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
239 |
bestPrefixes |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
240 |
] ifFalse:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
241 |
bestSelectors |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
242 |
] |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
243 |
]. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
244 |
|
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
245 |
selector := node selector. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
246 |
bestSelectors := findBest value:node value:selector. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
247 |
|
3357
7cfa9db9254e
fix: care for no parent message
Claus Gittinger <cg@exept.de>
parents:
3356
diff
changeset
|
248 |
parentNode := node parent. |
7cfa9db9254e
fix: care for no parent message
Claus Gittinger <cg@exept.de>
parents:
3356
diff
changeset
|
249 |
|
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
250 |
"/ if its a unary message AND the parent is a keyword node, look for parent completion too. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
251 |
(node selector isUnarySelector |
3357
7cfa9db9254e
fix: care for no parent message
Claus Gittinger <cg@exept.de>
parents:
3356
diff
changeset
|
252 |
and:[ parentNode notNil |
7cfa9db9254e
fix: care for no parent message
Claus Gittinger <cg@exept.de>
parents:
3356
diff
changeset
|
253 |
and:[ parentNode isMessage |
7cfa9db9254e
fix: care for no parent message
Claus Gittinger <cg@exept.de>
parents:
3356
diff
changeset
|
254 |
and:[ (selector2 := parentNode selector) isKeywordSelector ]]]) ifTrue:[ |
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
255 |
"/ srchClass2 := self lookupClassForMessage:parentNode inClass:cls. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
256 |
selector2 := selector2,selector. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
257 |
bestSelectors2 := findBest value:parentNode value:selector2. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
258 |
]. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
259 |
|
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
260 |
bestSelectors2 isEmptyOrNil ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
261 |
allBest := bestSelectors. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
262 |
] ifFalse:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
263 |
bestSelectors isEmptyOrNil ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
264 |
allBest := bestSelectors2 |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
265 |
] ifFalse:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
266 |
selectorInBest := (bestSelectors contains:[:sel | sel asLowercase startsWith:selector asLowercase]). |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
267 |
selector2InBest2 := (bestSelectors2 contains:[:sel | sel asLowercase startsWith:selector2 asLowercase]). |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
268 |
|
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
269 |
(selectorInBest not and:[ selector2InBest2 ]) ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
270 |
"/ selector2 is more likely |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
271 |
allBest := bestSelectors2 |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
272 |
] ifFalse:[ |
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
273 |
(selectorInBest and:[ selector2InBest2 not ]) ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
274 |
"/ selector more likely |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
275 |
allBest := bestSelectors |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
276 |
] ifFalse:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
277 |
"/ assume same likelyness |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
278 |
|
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
279 |
allBest := bestSelectors isEmpty |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
280 |
ifTrue:[ bestSelectors2 ] |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
281 |
ifFalse:[ bestSelectors , #(nil) , bestSelectors2 ]. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
282 |
] |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
283 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
284 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
285 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
286 |
|
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
287 |
allBest isEmptyOrNil ifTrue:[ ^ self ]. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
288 |
|
3545
1cbb9b58d37a
better message-selector completion
Claus Gittinger <cg@exept.de>
parents:
3543
diff
changeset
|
289 |
"/ the ones already sent in the code are moved to the top of the list. |
1cbb9b58d37a
better message-selector completion
Claus Gittinger <cg@exept.de>
parents:
3543
diff
changeset
|
290 |
allBest1 := allBest select:[:sel | selectorsSentInCode includes:sel]. |
1cbb9b58d37a
better message-selector completion
Claus Gittinger <cg@exept.de>
parents:
3543
diff
changeset
|
291 |
allBest2 := allBest reject:[:sel | selectorsSentInCode includes:sel]. |
1cbb9b58d37a
better message-selector completion
Claus Gittinger <cg@exept.de>
parents:
3543
diff
changeset
|
292 |
allBest1 isEmpty ifTrue:[ |
1cbb9b58d37a
better message-selector completion
Claus Gittinger <cg@exept.de>
parents:
3543
diff
changeset
|
293 |
allBest := allBest2. |
1cbb9b58d37a
better message-selector completion
Claus Gittinger <cg@exept.de>
parents:
3543
diff
changeset
|
294 |
] ifFalse:[ |
1cbb9b58d37a
better message-selector completion
Claus Gittinger <cg@exept.de>
parents:
3543
diff
changeset
|
295 |
allBest2 isEmpty ifTrue:[ |
1cbb9b58d37a
better message-selector completion
Claus Gittinger <cg@exept.de>
parents:
3543
diff
changeset
|
296 |
allBest := allBest1. |
1cbb9b58d37a
better message-selector completion
Claus Gittinger <cg@exept.de>
parents:
3543
diff
changeset
|
297 |
] ifFalse:[ |
1cbb9b58d37a
better message-selector completion
Claus Gittinger <cg@exept.de>
parents:
3543
diff
changeset
|
298 |
allBest := allBest1 , #(nil), allBest2. |
1cbb9b58d37a
better message-selector completion
Claus Gittinger <cg@exept.de>
parents:
3543
diff
changeset
|
299 |
] |
1cbb9b58d37a
better message-selector completion
Claus Gittinger <cg@exept.de>
parents:
3543
diff
changeset
|
300 |
]. |
1cbb9b58d37a
better message-selector completion
Claus Gittinger <cg@exept.de>
parents:
3543
diff
changeset
|
301 |
|
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
302 |
best := allBest first. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
303 |
allBest size > 1 ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
304 |
allBest size < 20 ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
305 |
|idx| |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
306 |
|
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
307 |
idx := (PopUpMenu labels:allBest) startUp. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
308 |
idx == 0 ifTrue:[ ^ self]. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
309 |
best := allBest at:idx. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
310 |
] ifFalse:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
311 |
best := Dialog request:'Matching selectors:' initialAnswer:best list:allBest. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
312 |
best isEmptyOrNil ifTrue:[^ self]. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
313 |
]. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
314 |
best = '-' ifTrue:[^ self]. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
315 |
]. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
316 |
|
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
317 |
false ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
318 |
srchClass notNil ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
319 |
implClass := srchClass whichClassIncludesSelector:best. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
320 |
] ifFalse:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
321 |
implClass := Smalltalk allClasses select:[:cls | (cls includesSelector:best) or:[cls class includesSelector:best]]. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
322 |
implClass size == 1 ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
323 |
implClass := implClass first. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
324 |
] ifFalse:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
325 |
implClass := nil |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
326 |
] |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
327 |
]. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
328 |
|
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
329 |
info := best storeString. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
330 |
implClass notNil ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
331 |
info := implClass name , ' >> ' , info. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
332 |
]. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
333 |
self information:info. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
334 |
]. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
335 |
|
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
336 |
best ~= selector ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
337 |
numArgs := best numArgs. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
338 |
(bestSelectors2 notEmptyOrNil and:[bestSelectors2 includes:best]) ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
339 |
selectorParts := parentNode selectorParts , node selectorParts. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
340 |
] ifFalse:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
341 |
selectorParts := node selectorParts. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
342 |
]. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
343 |
nSelParts := selectorParts size. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
344 |
|
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
345 |
newParts := best asCollectionOfSubstringsSeparatedBy:$:. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
346 |
newParts := newParts select:[:part | part size > 0]. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
347 |
|
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
348 |
codeView |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
349 |
undoableDo:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
350 |
|newCursorPosition stop| |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
351 |
|
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
352 |
numArgs > nSelParts ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
353 |
stop := selectorParts last stop. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
354 |
|
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
355 |
"/ append the rest ... |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
356 |
numArgs downTo:nSelParts+1 do:[:idx | |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
357 |
|newPart| |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
358 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
359 |
newPart := newParts at:idx. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
360 |
(best endsWith:$:) ifTrue:[ |
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
361 |
newPart := newPart , ':' |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
362 |
]. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
363 |
|
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
364 |
(codeView characterAtCharacterPosition:stop) == $: ifFalse:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
365 |
newPart := ':' , newPart. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
366 |
]. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
367 |
newPart := (codeView characterAtCharacterPosition:stop) asString , newPart. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
368 |
|
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
369 |
codeView replaceFromCharacterPosition:stop to:stop with:newPart. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
370 |
newCursorPosition isNil ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
371 |
newCursorPosition := stop + newPart size. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
372 |
] |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
373 |
] |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
374 |
]. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
375 |
|
3547 | 376 |
(nSelParts min:newParts size) downTo:1 do:[:idx | |
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
377 |
|newPart oldPartialToken start stop| |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
378 |
|
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
379 |
newPart := newParts at:idx. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
380 |
oldPartialToken := selectorParts at:idx. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
381 |
start := oldPartialToken start. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
382 |
stop := oldPartialToken stop. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
383 |
|
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
384 |
(best endsWith:$:) ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
385 |
(codeView characterAtCharacterPosition:stop+1) == $: ifFalse:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
386 |
newPart := newPart , ':' |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
387 |
] |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
388 |
] ifFalse:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
389 |
(codeView characterAtCharacterPosition:stop) == $: ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
390 |
newPart := newPart , ':' |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
391 |
] ifFalse:[ |
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
392 |
(codeView characterAtCharacterPosition:stop+1) isSeparator ifFalse:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
393 |
newPart := newPart , ' ' |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
394 |
] |
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
395 |
] |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
396 |
"/ codeView replaceFromCharacterPosition:start to:stop with:(newPart , ':'). |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
397 |
"/ ] ifFalse:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
398 |
"/ codeView replaceFromCharacterPosition:start to:stop with:newPart. |
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
399 |
]. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
400 |
|
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
401 |
codeView replaceFromCharacterPosition:start to:stop with:newPart. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
402 |
|
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
403 |
oldLen := stop - start + 1. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
404 |
newLen := newPart size. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
405 |
|
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
406 |
"/ codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
407 |
newCursorPosition isNil ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
408 |
newCursorPosition := stop + (newLen-oldLen). |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
409 |
]. |
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
410 |
]. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
411 |
codeView cursorToCharacterPosition:newCursorPosition. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
412 |
codeView cursorRight. "/ avoid going to the next line !! |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
413 |
codeView dontReplaceSelectionOnInput. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
414 |
] |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
415 |
info:'completion'. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
416 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
417 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
418 |
"Created: / 10-11-2006 / 13:18:27 / cg" |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
419 |
! |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
420 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
421 |
codeCompletionForMethod:node inClass:cls codeView:codeView |
3306
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
422 |
"completion in a methods selector pattern" |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
423 |
|
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
424 |
|crsrPos |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
425 |
selectorSoFar matchingSelectors |
3306
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
426 |
selectors distances best rest |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
427 |
allExistingMethods namesOfArguments |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
428 |
nameBag namesByCount| |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
429 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
430 |
crsrPos := codeView characterPositionOfCursor - 1. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
431 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
432 |
selectorSoFar := ''. |
3306
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
433 |
node selectorParts doWithIndex:[:partToken :argNr| |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
434 |
|part| |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
435 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
436 |
part := partToken value. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
437 |
selectorSoFar := selectorSoFar , part. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
438 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
439 |
(crsrPos >= partToken start |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
440 |
and:[crsrPos <= partToken stop]) ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
441 |
matchingSelectors := Smalltalk allClasses |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
442 |
inject:(Set new) |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
443 |
into:[:theSet :eachClass | |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
444 |
|md| |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
445 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
446 |
cls isMeta ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
447 |
md := eachClass theMetaclass methodDictionary |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
448 |
] ifFalse:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
449 |
md := eachClass theNonMetaclass methodDictionary |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
450 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
451 |
theSet addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]). |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
452 |
theSet. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
453 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
454 |
selectors := matchingSelectors asOrderedCollection. |
3306
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
455 |
"/ if there is only one, and user has already entered it, he might want to complete the argument-name |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
456 |
(selectors size == 1 |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
457 |
and:[selectors first = selectorSoFar]) ifTrue:[ |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
458 |
allExistingMethods := (Smalltalk allImplementorsOf:selectorSoFar asSymbol) |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
459 |
collect:[:cls | cls compiledMethodAt:selectorSoFar asSymbol]. |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
460 |
namesOfArguments := allExistingMethods collect:[:eachMethod | eachMethod methodArgNames]. |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
461 |
nameBag := Bag new. |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
462 |
namesOfArguments do:[:eachNameVector | nameBag add:(eachNameVector at:argNr)]. |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
463 |
namesByCount := nameBag valuesAndCounts sort:[:a :b | a value < b value]. |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
464 |
"/ take the one which occurs most often |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
465 |
best := self askUserForCompletion:'argument' for:codeView from:(namesByCount collect:[:a | a key]). |
2376 | 466 |
|
3306
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
467 |
codeView |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
468 |
undoableDo:[ |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
469 |
(crsrPos+1) >= codeView contents size ifTrue:[ |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
470 |
codeView paste:best. |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
471 |
] ifFalse:[ |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
472 |
codeView insertString:best atCharacterPosition:crsrPos+1. |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
473 |
] |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
474 |
] |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
475 |
info:'completion'. |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
476 |
codeView cursorToCharacterPosition:(crsrPos + best size - 1). |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
477 |
] ifFalse:[ |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
478 |
distances := selectors collect:[:each | each spellAgainst:selectorSoFar]. |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
479 |
distances sortWith:selectors. |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
480 |
selectors reverse. |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
481 |
best := self askUserForCompletion:'selector' for:codeView from:selectors. |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
482 |
best isNil ifTrue:[^ self]. |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
483 |
|
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
484 |
rest := best copyFrom:selectorSoFar size. |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
485 |
|
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
486 |
codeView |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
487 |
undoableDo:[ |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
488 |
codeView |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
489 |
replaceFromCharacterPosition:crsrPos |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
490 |
to:crsrPos |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
491 |
with:rest |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
492 |
] |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
493 |
info:'completion'. |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
494 |
codeView cursorToCharacterPosition:(crsrPos + rest size - 1). |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
495 |
]. |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
496 |
codeView cursorRight. "/ kludge to make it visible |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
497 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
498 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
499 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
500 |
"Modified: / 04-07-2006 / 18:48:26 / fm" |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
501 |
"Created: / 10-11-2006 / 13:46:44 / cg" |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
502 |
! |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
503 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
504 |
codeCompletionForVariable:node inClass:cls codeView:codeView |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
505 |
|nonMetaClass crsrPos nm |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
506 |
allVariables allDistances best nodeVal |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
507 |
char start stop oldLen newLen oldVar |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
508 |
getDistanceComputeBlockWithWeight addWithFactorBlock names allTheBest bestAssoc |
3551
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
509 |
globalFactor localFactor selectorOfMessageToNode tree implementors argIdx namesUsed kwPart| |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
510 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
511 |
nonMetaClass := cls theNonMetaclass. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
512 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
513 |
nm := node name. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
514 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
515 |
"/ if we are behind the variable and a space has already been entered, |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
516 |
"/ the user is probably looking for a message selector. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
517 |
"/ If the variable represents a global, present its instance creation messages |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
518 |
crsrPos := codeView characterPositionOfCursor. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
519 |
char := codeView characterAtCharacterPosition:crsrPos-1. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
520 |
char isSeparator ifTrue:[ |
3543 | 521 |
nodeVal := cls topNameSpace at:nm asSymbol ifAbsent:[Smalltalk at:nm asSymbol]. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
522 |
nodeVal isBehavior ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
523 |
|methods menu exitKey idx| |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
524 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
525 |
methods := nodeVal class methodDictionary values |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
526 |
select:[:m | |cat| |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
527 |
cat := m category asLowercase. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
528 |
cat = 'instance creation' |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
529 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
530 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
531 |
menu := PopUpMenu labels:(methods collect:[:each | each selector]). |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
532 |
menu hideOnKeyFilter:[:key | |hide| |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
533 |
hide := ( #( CursorDown CursorUp Escape Return ) includes: key) not. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
534 |
hide ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
535 |
exitKey := key. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
536 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
537 |
hide]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
538 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
539 |
idx := menu startUp. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
540 |
idx == 0 ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
541 |
exitKey notNil ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
542 |
codeView keyPress:exitKey x:0 y:0. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
543 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
544 |
^ self |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
545 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
546 |
best := (methods at:idx) selector. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
547 |
codeView |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
548 |
undoableDo:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
549 |
codeView insertString:best atCharacterPosition:crsrPos. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
550 |
codeView cursorToCharacterPosition:crsrPos+best size. |
3362 | 551 |
] |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
552 |
info:'completion'. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
553 |
^ self. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
554 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
555 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
556 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
557 |
(node parent notNil and:[node parent isMessage]) ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
558 |
node == node parent receiver ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
559 |
selectorOfMessageToNode := node parent selector |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
560 |
] |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
561 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
562 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
563 |
getDistanceComputeBlockWithWeight := |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
564 |
[:weight | |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
565 |
[:each | |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
566 |
|dist factor| |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
567 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
568 |
dist := each spellAgainst:nm. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
569 |
factor := 1. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
570 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
571 |
(each startsWith:nm) ifTrue:[ |
3551
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
572 |
factor := 6 * nm size. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
573 |
] ifFalse:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
574 |
(each asLowercase startsWith:nm asLowercase) ifTrue:[ |
3551
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
575 |
factor := 4 * nm size. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
576 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
577 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
578 |
dist := dist + (weight*factor). |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
579 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
580 |
each -> (dist * weight) |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
581 |
] |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
582 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
583 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
584 |
addWithFactorBlock := |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
585 |
[:names :factor | |namesToAdd| |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
586 |
namesToAdd := names select:[:nameToAdd | nameToAdd ~= nm ]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
587 |
namesToAdd := namesToAdd reject:[:each | allVariables includes:each ]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
588 |
allVariables addAll:namesToAdd. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
589 |
allDistances addAll:(namesToAdd collect:(getDistanceComputeBlockWithWeight value:factor)). |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
590 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
591 |
|
3550
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
592 |
nm isUppercaseFirst ifTrue:[ |
3551
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
593 |
globalFactor := 2. "/ favour globals |
3550
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
594 |
localFactor := 1. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
595 |
] ifFalse:[ |
3551
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
596 |
globalFactor := 1. "/ favour locals |
3550
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
597 |
localFactor := 2. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
598 |
]. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
599 |
|
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
600 |
allVariables := OrderedCollection new. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
601 |
allDistances := OrderedCollection new. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
602 |
|
3550
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
603 |
"/ are we in the methods selector spec ? |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
604 |
(node parent notNil |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
605 |
and:[node parent isMethod |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
606 |
and:[node parent arguments includes:node]]) ifTrue:[ |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
607 |
"/ now thats cool: look how the naem of this argument is in other implementations |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
608 |
"/ of this method, and take that as a basis of the selection |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
609 |
|
3550
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
610 |
implementors := SystemBrowser |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
611 |
findImplementorsOf:(node parent selector) |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
612 |
in:(Smalltalk allClasses) |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
613 |
ignoreCase:false. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
614 |
"/ which argument is it |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
615 |
argIdx := node parent arguments indexOf:node. |
3551
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
616 |
namesUsed := (implementors |
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
617 |
collect:[:eachImplementor | |
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
618 |
|parseTree| |
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
619 |
parseTree := eachImplementor parseTree. |
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
620 |
(parseTree notNil and:[parseTree arguments size > 0]) |
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
621 |
ifFalse:nil |
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
622 |
ifTrue:[ (parseTree arguments at:argIdx) name] ] |
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
623 |
thenSelect:[:a | a notNil]) asSet. |
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
624 |
|
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
625 |
addWithFactorBlock value:namesUsed value:(2 * localFactor). |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
626 |
|
3551
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
627 |
"/ also, look for the keyword before the argument, |
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
628 |
"/ and see if there is such an instVar |
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
629 |
"/ if so, add it with -Arg |
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
630 |
node parent selector isKeyword ifTrue:[ |
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
631 |
kwPart := node parent selector keywords at:argIdx. |
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
632 |
(cls allInstVarNames includes:(kwPart copyWithoutLast:1)) ifTrue:[ |
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
633 |
addWithFactorBlock |
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
634 |
value:(cls allInstVarNames collect:[:nm| nm,'Arg']) |
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
635 |
value:(1 * localFactor). |
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
636 |
]. |
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
637 |
]. |
0c83710ae45e
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3550
diff
changeset
|
638 |
|
3550
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
639 |
] ifFalse:[ |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
640 |
|
3550
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
641 |
"/ locals in the block/method |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
642 |
names := node allVariablesOnScope. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
643 |
"/ if there were no variables (due to a parse error) |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
644 |
"/ do another parse and see what we have |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
645 |
names isEmpty ifTrue:[ |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
646 |
tree := self treeForCode:(codeView contentsAsString string) allowErrors:true. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
647 |
"/ better if we already have a body (include locals then) |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
648 |
"/ otherwise, only the arguments are considered |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
649 |
tree notNil ifTrue:[ |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
650 |
names := (tree body ? tree) allVariablesOnScope. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
651 |
] |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
652 |
]. |
3470
5cbf651bb214
name completion: care also for private class names
Claus Gittinger <cg@exept.de>
parents:
3366
diff
changeset
|
653 |
|
3550
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
654 |
addWithFactorBlock value:names value:(4 * localFactor). |
2376 | 655 |
|
3550
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
656 |
"/ instance variables |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
657 |
addWithFactorBlock value:cls instVarNames value:(3 * localFactor). |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
658 |
|
3550
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
659 |
"/ inherited instance variables |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
660 |
cls superclass notNil ifTrue:[ |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
661 |
addWithFactorBlock value:cls superclass allInstVarNames value:(2.5 * localFactor). |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
662 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
663 |
|
3550
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
664 |
selectorOfMessageToNode notNil ifTrue:[ |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
665 |
|names responders nonResponders| |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
666 |
|
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
667 |
"/ responding to that messsage |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
668 |
|
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
669 |
"/ private classes |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
670 |
addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix]) |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
671 |
value:(1.75 * globalFactor). |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
672 |
|
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
673 |
"/ class variables |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
674 |
names := nonMetaClass classVarNames. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
675 |
responders := names select:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
676 |
nonResponders := names reject:[:classVar | (nonMetaClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
677 |
|
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
678 |
addWithFactorBlock value:responders value:(1.5 * globalFactor). |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
679 |
addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor). |
3550
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
680 |
|
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
681 |
"/ superclass var names |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
682 |
nonMetaClass allSuperclassesDo:[:superClass | |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
683 |
names := superClass classVarNames. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
684 |
responders := names select:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
685 |
nonResponders := names reject:[:classVar | (superClass classVarAt:classVar) respondsTo:selectorOfMessageToNode]. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
686 |
|
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
687 |
addWithFactorBlock value:responders value:(1 * globalFactor). |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
688 |
addWithFactorBlock value:nonResponders value:(0.5 * 1 * globalFactor). |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
689 |
]. |
3470
5cbf651bb214
name completion: care also for private class names
Claus Gittinger <cg@exept.de>
parents:
3366
diff
changeset
|
690 |
|
3550
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
691 |
"/ namespace vars |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
692 |
cls nameSpace ~~ Smalltalk ifTrue:[ |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
693 |
names := cls topNameSpace keys. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
694 |
names := names reject:[:nm | nm includes:$:]. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
695 |
names := names select:[:nm | nm isUppercaseFirst ]. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
696 |
responders := names select:[:nsVar | |c| c := cls topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
697 |
nonResponders := names reject:[:nsVar | |c| c := cls topNameSpace at:nsVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
698 |
addWithFactorBlock value:responders value:(1.5 * globalFactor). |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
699 |
addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor). |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
700 |
]. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
701 |
"/ globals |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
702 |
names := Smalltalk keys. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
703 |
names := names reject:[:nm | nm includes:$:]. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
704 |
names := names select:[:nm | nm isUppercaseFirst ]. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
705 |
responders := names select:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
706 |
nonResponders := names reject:[:glblVar | |c| c := Smalltalk at:glblVar. c isBehavior not or:[c isLoaded and:[c respondsTo:selectorOfMessageToNode]]]. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
707 |
addWithFactorBlock value:responders value:(1.5 * globalFactor). |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
708 |
addWithFactorBlock value:nonResponders value:(0.5 * 1.5 * globalFactor). |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
709 |
] ifFalse:[ |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
710 |
"/ private classes |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
711 |
addWithFactorBlock value:(nonMetaClass privateClasses collect:[:cls | cls nameWithoutPrefix]) |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
712 |
value:(1.75 * globalFactor). |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
713 |
|
3550
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
714 |
"/ class variables |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
715 |
addWithFactorBlock value:nonMetaClass classVarNames value:(1.5 * globalFactor). |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
716 |
cls superclass notNil ifTrue:[ |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
717 |
addWithFactorBlock value:nonMetaClass superclass allClassVarNames value:(1 * globalFactor). |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
718 |
]. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
719 |
|
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
720 |
"/ namespace vars |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
721 |
cls nameSpace ~~ Smalltalk ifTrue:[ |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
722 |
names := cls nameSpace isNameSpace ifTrue:[cls nameSpace keys] ifFalse:[cls nameSpace privateClasses collect:[:c | c nameWithoutPrefix]]. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
723 |
names := names select:[:nm | nm isUppercaseFirst ]. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
724 |
addWithFactorBlock value:names value:(1.5 * globalFactor). |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
725 |
]. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
726 |
"/ globals |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
727 |
names := Smalltalk keys. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
728 |
names := names select:[:nm | nm isUppercaseFirst ]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
729 |
addWithFactorBlock value:names value:(1.5 * globalFactor). |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
730 |
]. |
3550
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
731 |
|
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
732 |
"/ pseudos - assuming that thisContext is seldom used. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
733 |
"/ also assuming, that nil is short so its usually typed in. |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
734 |
addWithFactorBlock value:#('self') value:(2.5 * localFactor). |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
735 |
addWithFactorBlock value:#('nil') value:(0.5 * localFactor). |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
736 |
addWithFactorBlock value:#('super' 'false') value:(2 * localFactor). |
34c8ab9f403f
much better method-argument-name completion
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
737 |
addWithFactorBlock value:#('thisContext') value:(1 * localFactor). |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
738 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
739 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
740 |
bestAssoc := allDistances at:1. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
741 |
bestAssoc := allDistances inject:bestAssoc into:[:el :best | el value > best value |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
742 |
ifTrue:[el] |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
743 |
ifFalse:[best] |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
744 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
745 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
746 |
allDistances sort:[:a :b | a value > b value]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
747 |
allTheBest := allDistances select:[:entry | entry value >= (bestAssoc value * 0.8)]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
748 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
749 |
best := self askUserForCompletion:'variable' for:codeView from:(allTheBest collect:[:assoc | assoc key]). |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
750 |
best isNil ifTrue:[^ self]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
751 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
752 |
"/ self showInfo:best. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
753 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
754 |
start := node start. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
755 |
stop := node stop. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
756 |
oldVar := (codeView textFromCharacterPosition:start to:stop) asString string withoutSeparators. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
757 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
758 |
codeView |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
759 |
undoableDo:[ codeView replaceFromCharacterPosition:start to:stop with:best ] |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
760 |
info:'completion'. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
761 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
762 |
(best startsWith:oldVar) ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
763 |
oldLen := stop - start + 1. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
764 |
newLen := best size. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
765 |
codeView selectFromCharacterPosition:start+oldLen to:start+newLen-1. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
766 |
codeView dontReplaceSelectionOnInput |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
767 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
768 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
769 |
"Created: / 10-11-2006 / 13:16:33 / cg" |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
770 |
"Modified: / 16-11-2006 / 14:15:59 / cg" |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
771 |
! |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
772 |
|
3300 | 773 |
findNodeForInterval:interval in:source |
774 |
|tree node| |
|
775 |
||
776 |
interval isEmpty ifTrue: [^ nil]. |
|
777 |
RBParser isNil ifTrue: [^ nil]. |
|
778 |
||
3475
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
779 |
source = LastSource ifTrue:[ |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
780 |
tree := LastParseTree. |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
781 |
] ifFalse:[ |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
782 |
tree := RBParser |
3300 | 783 |
parseMethod:source |
784 |
onError: [:str :err ":nodesSoFar" | ^ nil]. |
|
3475
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
785 |
|
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
786 |
tree isNil ifTrue:[^ nil]. |
3300 | 787 |
|
3475
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
788 |
LastSource := source. |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
789 |
LastParseTree := tree. |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
790 |
]. |
3300 | 791 |
|
792 |
node := tree whichNodeIsContainedBy:interval. |
|
793 |
node isNil ifTrue: [ |
|
3475
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
794 |
node := tree bestNodeFor: interval. |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
795 |
node isNil ifTrue: [ |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
796 |
node := DoWhatIMeanSupport findNodeIn:tree forInterval:interval |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
797 |
]. |
3300 | 798 |
]. |
799 |
^ node |
|
800 |
||
801 |
"Modified: / 16-11-2006 / 19:04:03 / cg" |
|
802 |
! |
|
803 |
||
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
804 |
findNodeForInterval:interval in:source allowErrors:allowErrors |
3306
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
805 |
|tree "errCount"| |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
806 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
807 |
interval isEmpty ifTrue: [^ nil]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
808 |
RBParser isNil ifTrue: [^ nil]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
809 |
|
3475
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
810 |
source = LastSource ifTrue:[ |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
811 |
tree := LastParseTree. |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
812 |
] ifFalse:[ |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
813 |
tree := RBParser |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
814 |
parseMethod:source |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
815 |
onError: [:str :err :nodesSoFar | |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
816 |
|nodes| |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
817 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
818 |
allowErrors ifTrue:[ |
3306
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
819 |
nodes := nodesSoFar |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
820 |
collect:[:nd | nd whichNodeIntersects:interval] |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
821 |
thenSelect:[:nd | nd notNil ]. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
822 |
nodes size == 1 ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
823 |
^ nodes first |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
824 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
825 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
826 |
^ nil] |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
827 |
rememberNodes:true. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
828 |
"/ onError: [:str :err | errCount := (errCount?0) + 1. self halt.] |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
829 |
"/ proceedAfterError:true. |
3475
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
830 |
tree isNil ifTrue:[^ nil]. |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
831 |
LastSource := source. |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
832 |
LastParseTree := tree. |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
833 |
]. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
834 |
|
3306
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
835 |
^ self findNodeForInterval:interval inParseTree:tree. |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
836 |
! |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
837 |
|
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
838 |
findNodeForInterval:interval inParseTree:parseTree |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
839 |
|node| |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
840 |
|
3306
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
841 |
interval isEmpty ifTrue: [^ nil]. |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
842 |
parseTree isNil ifTrue:[^ nil]. |
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
843 |
|
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
844 |
node := parseTree whichNodeIsContainedBy:interval. |
3475
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
845 |
node isNil ifTrue:[ |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
846 |
node := parseTree whichNodeIntersects:interval. |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
847 |
]. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
848 |
node isNil ifTrue: [ |
3306
40e860fd2f02
argument-name completion in a methods selector pattern
Claus Gittinger <cg@exept.de>
parents:
3303
diff
changeset
|
849 |
node := self findNodeIn:parseTree forInterval:interval |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
850 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
851 |
^ node |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
852 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
853 |
"Modified: / 10-11-2006 / 13:13:58 / cg" |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
854 |
! |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
855 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
856 |
findNodeIn:tree forInterval:interval |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
857 |
|node wouldReturn| |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
858 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
859 |
node := nil. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
860 |
tree nodesDo:[:each | |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
861 |
(each intersectsInterval:interval) ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
862 |
(node isNil or:[node == each parent]) ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
863 |
node := each |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
864 |
] ifFalse:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
865 |
(node parent notNil |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
866 |
and:[node parent isCascade and:[each parent isCascade]]) ifFalse:[^ nil] |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
867 |
] |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
868 |
] ifFalse:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
869 |
node notNil ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
870 |
"/ already found one - beyond that one; leave |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
871 |
wouldReturn notNil ifTrue:[wouldReturn := node]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
872 |
] |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
873 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
874 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
875 |
"/ (wouldReturn notNil and:[wouldReturn ~~ node]) ifTrue:[self halt]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
876 |
^ node |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
877 |
|
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
878 |
"Modified: / 20-11-2006 / 12:31:12 / cg" |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
879 |
! |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
880 |
|
3356
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
881 |
lookupClassForMessage:node inClass:classProvidingNamespace |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
882 |
|receiver nm nodeVal| |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
883 |
|
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
884 |
receiver := node receiver. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
885 |
receiver isVariable ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
886 |
nm := receiver name. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
887 |
nm = 'self' ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
888 |
^ classProvidingNamespace |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
889 |
]. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
890 |
nm = 'super' ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
891 |
^ classProvidingNamespace superclass |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
892 |
]. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
893 |
nm first isUppercase ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
894 |
"/ wouldn't it be better to simply 'evaluate' the variable ? |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
895 |
nodeVal := Parser new evaluate:nm in:nil receiver:(classProvidingNamespace basicNew). |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
896 |
|
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
897 |
"/ (Smalltalk includesKey:nm asSymbol) ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
898 |
"/ nodeVal := Smalltalk at:nm asSymbol. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
899 |
"/ ]. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
900 |
nodeVal notNil ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
901 |
^ nodeVal class |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
902 |
] |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
903 |
] |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
904 |
]. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
905 |
receiver isLiteral ifTrue:[ |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
906 |
^ receiver value class |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
907 |
]. |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
908 |
^ nil |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
909 |
! |
b1e3ccd1bcf2
better messageSelector completion
Claus Gittinger <cg@exept.de>
parents:
3331
diff
changeset
|
910 |
|
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
911 |
treeForCode:source allowErrors:allowErrors |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
912 |
|tree| |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
913 |
|
3475
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
914 |
source = LastSource ifTrue:[ |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
915 |
tree := LastParseTree. |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
916 |
] ifFalse:[ |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
917 |
tree := RBParser |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
918 |
parseMethod:source |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
919 |
onError: [:str :err :nodesSoFar :parser| |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
920 |
allowErrors ifTrue:[ |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
921 |
^ parser currentMethodNode |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
922 |
]. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
923 |
^ nil |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
924 |
] |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
925 |
proceedAfterError:false |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
926 |
rememberNodes:true. |
3475
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
927 |
tree isNil ifTrue:[^ nil]. |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
928 |
LastSource := source. |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
929 |
LastParseTree := tree. |
8ed28a1e4e37
cache last parse tree (for flyByHelp)
Claus Gittinger <cg@exept.de>
parents:
3470
diff
changeset
|
930 |
]. |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
931 |
^ tree |
2376 | 932 |
! ! |
933 |
||
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
934 |
!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
|
935 |
|
2975 | 936 |
classCategoryCompletion:aPartialCategory inEnvironment:anEnvironment |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
937 |
"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
|
938 |
2 entries: 1st: the best (longest) match |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
939 |
2nd: collection consisting of matching categories" |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
940 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
941 |
|matches best lcName| |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
942 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
943 |
matches := IdentitySet new. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
944 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
945 |
"/ search for exact match |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
946 |
anEnvironment allClassesDo:[:aClass | |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
947 |
|category| |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
948 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
949 |
category := aClass category. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
950 |
(category notNil and:[category startsWith:aPartialCategory]) ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
951 |
matches add:category |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
952 |
] |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
953 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
954 |
matches isEmpty ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
955 |
"/ search for case-ignoring match |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
956 |
lcName := aPartialCategory asLowercase. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
957 |
anEnvironment allClassesDo:[:aClass | |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
958 |
|category| |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
959 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
960 |
category := aClass category. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
961 |
(category notNil and:[category asLowercase startsWith:lcName]) ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
962 |
matches add:category |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
963 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
964 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
965 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
966 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
967 |
matches isEmpty ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
968 |
^ Array with:aPartialCategory with:(Array with:aPartialCategory) |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
969 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
970 |
matches size == 1 ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
971 |
^ Array with:matches first with:(matches asArray) |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
972 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
973 |
matches := matches asSortedCollection. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
974 |
best := matches longestCommonPrefix. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
975 |
^ 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
|
976 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
977 |
" |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
978 |
Smalltalk classCategoryCompletion:'Sys' |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
979 |
Smalltalk classCategoryCompletion:'System' |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
980 |
Smalltalk classCategoryCompletion:'System-BinaryStorage' |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
981 |
" |
2975 | 982 |
|
983 |
"Created: / 10-08-2006 / 13:06:45 / cg" |
|
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
984 |
! |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
985 |
|
2830 | 986 |
classNameEntryCompletionBlock |
987 |
"this block can be used in a dialog to perform className completion" |
|
988 |
||
2977 | 989 |
^ self entryCompletionBlockFor:#'classnameCompletion:inEnvironment:' |
2830 | 990 |
|
2977 | 991 |
"Modified: / 10-08-2006 / 13:22:02 / cg" |
2830 | 992 |
! |
993 |
||
2975 | 994 |
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
|
995 |
"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
|
996 |
2 entries: 1st: the best (longest) match |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
997 |
2nd: collection consisting of matching names" |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
998 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
999 |
|searchName matches matchedNamesWithoutPrefix ignCaseMatches best isMatchString cls nsPrefix |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1000 |
others lcSearchName tryToMatch idx words w1 w2 rslt bestMatch| |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1001 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1002 |
aPartialClassName isEmpty ifTrue:[ |
2975 | 1003 |
matches := Smalltalk allClassesForWhich:filterBlock. |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1004 |
^ Array with:aPartialClassName with:#() |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1005 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1006 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1007 |
(words := aPartialClassName asCollectionOfWords) size > 1 ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1008 |
w1 := words first. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1009 |
w2 := words second. |
2975 | 1010 |
rslt := self classnameCompletion:w1 filter:filterBlock inEnvironment:anEnvironment. |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1011 |
bestMatch := rslt first. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1012 |
matches := rslt second. |
3549 | 1013 |
('class' copyTo:(w2 size min:5)) = w2 ifTrue:[ |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1014 |
matches := matches collect:[:m | m , ' class']. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1015 |
bestMatch := bestMatch , ' class'. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1016 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1017 |
^ Array with:bestMatch with:matches |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1018 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1019 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1020 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1021 |
(aPartialClassName startsWith:'Smalltalk::') ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1022 |
nsPrefix := 'Smalltalk::'. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1023 |
searchName := aPartialClassName copyFrom:'Smalltalk::' size + 1 |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1024 |
] ifFalse:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1025 |
nsPrefix := ''. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1026 |
searchName := aPartialClassName. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1027 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1028 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1029 |
(searchName at:1) isLowercase ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1030 |
searchName := searchName copy asUppercaseFirst |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1031 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1032 |
lcSearchName := searchName asLowercase. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1033 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1034 |
isMatchString := searchName includesMatchCharacters. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1035 |
matches := OrderedCollection new. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1036 |
matchedNamesWithoutPrefix := Set new. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1037 |
ignCaseMatches := OrderedCollection new. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1038 |
others := OrderedCollection new. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1039 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1040 |
tryToMatch := [:className :fullClassName| |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1041 |
|addIt lcClassName| |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1042 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1043 |
isMatchString ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1044 |
addIt := searchName match:className |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1045 |
] ifFalse:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1046 |
addIt := className startsWith:searchName. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1047 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1048 |
addIt ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1049 |
matches add:(nsPrefix , fullClassName). |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1050 |
matchedNamesWithoutPrefix add:className. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1051 |
] ifFalse:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1052 |
"/ try ignoring case |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1053 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1054 |
isMatchString ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1055 |
addIt := searchName match:className ignoreCase:true |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1056 |
] ifFalse:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1057 |
lcClassName := className asLowercase. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1058 |
addIt := lcClassName startsWith:lcSearchName. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1059 |
addIt ifFalse:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1060 |
others add:className |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1061 |
] |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1062 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1063 |
addIt ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1064 |
ignCaseMatches add:(nsPrefix , fullClassName). |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1065 |
matchedNamesWithoutPrefix add:className. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1066 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1067 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1068 |
addIt |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1069 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1070 |
|
2975 | 1071 |
anEnvironment allClassesForWhich:filterBlock do:[:aClass | |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1072 |
|addIt fullClassName classNameWithoutPrefix| |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1073 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1074 |
aClass isMeta ifFalse:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1075 |
fullClassName := aClass name. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1076 |
classNameWithoutPrefix := aClass nameWithoutPrefix. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1077 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1078 |
addIt := tryToMatch value:fullClassName value:fullClassName. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1079 |
addIt ifFalse:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1080 |
classNameWithoutPrefix ~~ fullClassName ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1081 |
tryToMatch value:classNameWithoutPrefix value:fullClassName. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1082 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1083 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1084 |
] |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1085 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1086 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1087 |
matches isEmpty ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1088 |
matches := ignCaseMatches |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1089 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1090 |
"/ matches isEmpty ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1091 |
"/ | nearBy | |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1092 |
"/ nearBy := SortedCollection new sortBlock:[:a :b | a key < b key]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1093 |
"/ others do:[:className | |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1094 |
"/ |lcClassName dist cmpName| |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1095 |
"/ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1096 |
"/ lcClassName := className asLowercase. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1097 |
"/ dist := lcClassName levenshteinTo:lcSearchName s:9 k:1 c:0 i:9 d:2. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1098 |
"/ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1099 |
"/ cmpName := lcClassName copyTo:(lcSearchName size min:lcClassName size). |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1100 |
"/ dist := dist min:(cmpName levenshteinTo:lcSearchName s:9 k:1 c:0 i:9 d:2). |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1101 |
"/ cmpName := lcClassName copyTo:(lcSearchName size + 1 min:lcClassName size). |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1102 |
"/ dist := dist min:(cmpName levenshteinTo:lcSearchName s:9 k:1 c:0 i:9 d:2). |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1103 |
"/ dist < 4 ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1104 |
"/ nearBy add:( dist -> (nsPrefix , className) ). |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1105 |
"/ ] |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1106 |
"/ ]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1107 |
"/ matches := nearBy collect:[:eachPair | eachPair value]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1108 |
"/ ]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1109 |
matches isEmpty ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1110 |
^ Array with:searchName with:(Array with:searchName) |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1111 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1112 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1113 |
matches size == 1 ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1114 |
best := matches first. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1115 |
^ 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
|
1116 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1117 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1118 |
matches |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1119 |
sort:[:name1 :name2 | |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1120 |
"name1 comes before:name2 iff" |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1121 |
((name2 includes:$:) and:[(name1 includes:$:) not]) |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1122 |
or:[ ((name1 includes:$:) == (name2 includes:$:)) |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1123 |
and:[ (name1 size < name2 size) |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1124 |
or: [ name1 < name2 ]] |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1125 |
] |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1126 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1127 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1128 |
isMatchString ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1129 |
best := searchName. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1130 |
] ifFalse:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1131 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1132 |
best := matches longestCommonPrefix. |
3198
fea29ae859c9
classnamecompletion fixed when namespace is involved
Claus Gittinger <cg@exept.de>
parents:
3135
diff
changeset
|
1133 |
best size < aPartialClassName size "best size == 0" ifTrue:[ |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1134 |
best := matchedNamesWithoutPrefix longestCommonPrefix. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1135 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1136 |
best size == 0 ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1137 |
"if tried again, return next match" |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1138 |
idx := ((matches indexOf:aPartialClassName) + 1) \\ matches size. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1139 |
idx ~~ 1 ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1140 |
^ Array with:(matches at:idx) with:(matches asArray) |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1141 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1142 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1143 |
best size < aPartialClassName size ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1144 |
best := aPartialClassName. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1145 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1146 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1147 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1148 |
cls := anEnvironment classNamed:best. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1149 |
(cls isBehavior and:[cls isNameSpace]) ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1150 |
(matches conform:[:each | each = best |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1151 |
or:[each startsWith:(best , '::')]]) |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1152 |
ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1153 |
best := best , '::' |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1154 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1155 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1156 |
^ 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
|
1157 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1158 |
" |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1159 |
Smalltalk classnameCompletion:'Arr' |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1160 |
Smalltalk classnameCompletion:'Arra' |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1161 |
Smalltalk classnameCompletion:'arra' |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1162 |
Smalltalk classnameCompletion:'*rray' |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1163 |
" |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1164 |
|
2975 | 1165 |
"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
|
1166 |
! |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1167 |
|
2975 | 1168 |
classnameCompletion:aPartialClassName inEnvironment:anEnvironment |
1169 |
"given a partial classname, return an array consisting of |
|
1170 |
2 entries: 1st: the best (longest) match |
|
1171 |
2nd: collection consisting of matching names" |
|
1172 |
||
1173 |
^ self |
|
1174 |
classnameCompletion:aPartialClassName |
|
1175 |
filter:[:cls | true] |
|
1176 |
inEnvironment:anEnvironment |
|
1177 |
||
1178 |
" |
|
1179 |
Smalltalk classnameCompletion:'Arr' |
|
1180 |
Smalltalk classnameCompletion:'Arra' |
|
1181 |
Smalltalk classnameCompletion:'arra' |
|
1182 |
Smalltalk classnameCompletion:'*rray' |
|
1183 |
" |
|
1184 |
||
1185 |
"Created: / 24-11-1995 / 17:24:45 / cg" |
|
1186 |
"Modified: / 10-08-2006 / 13:01:30 / cg" |
|
1187 |
! |
|
1188 |
||
2977 | 1189 |
entryCompletionBlockFor:completionSelector |
1190 |
"this block can be used in a dialog to perform className completion" |
|
1191 |
||
1192 |
^ [:contents :field | |
|
1193 |
|s what m| |
|
1194 |
||
1195 |
s := contents withoutSpaces. |
|
1196 |
field topView withCursor:(Cursor questionMark) do:[ |
|
1197 |
what := self perform:completionSelector with:s with:Smalltalk. |
|
1198 |
]. |
|
1199 |
field contents:(what first). |
|
1200 |
(what at:2) size ~~ 1 ifTrue:[ |
|
1201 |
field device beep |
|
1202 |
] |
|
1203 |
]. |
|
1204 |
||
1205 |
"Created: / 10-08-2006 / 13:21:37 / cg" |
|
1206 |
! |
|
1207 |
||
2975 | 1208 |
globalNameCompletion:aPartialGlobalName inEnvironment:anEnvironment |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1209 |
"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
|
1210 |
2 entries: 1st: the best (longest) match |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1211 |
2nd: collection consisting of matching names" |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1212 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1213 |
|searchName matches ignCaseMatches best isMatchString| |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1214 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1215 |
searchName := aPartialGlobalName. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1216 |
searchName isEmpty ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1217 |
^ Array with:searchName with:#() |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1218 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1219 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1220 |
(searchName at:1) isLowercase ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1221 |
searchName := searchName copy asUppercaseFirst |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1222 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1223 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1224 |
isMatchString := searchName includesMatchCharacters. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1225 |
matches := OrderedCollection new. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1226 |
ignCaseMatches := OrderedCollection new. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1227 |
anEnvironment keysDo:[:aGlobalName | |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1228 |
| addIt| |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1229 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1230 |
isMatchString ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1231 |
addIt := searchName match:aGlobalName |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1232 |
] ifFalse:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1233 |
addIt := aGlobalName startsWith:searchName |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1234 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1235 |
addIt ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1236 |
matches add:aGlobalName |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1237 |
] ifFalse:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1238 |
"/ try ignoring case |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1239 |
isMatchString ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1240 |
addIt := searchName match:aGlobalName ignoreCase:true |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1241 |
] ifFalse:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1242 |
addIt := aGlobalName asLowercase startsWith:searchName asLowercase |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1243 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1244 |
addIt ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1245 |
ignCaseMatches add:aGlobalName |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1246 |
] |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1247 |
] |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1248 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1249 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1250 |
matches isEmpty ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1251 |
matches := ignCaseMatches |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1252 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1253 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1254 |
matches isEmpty ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1255 |
^ Array with:searchName with:(Array with:searchName) |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1256 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1257 |
matches size == 1 ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1258 |
^ Array with:matches first with:(matches asArray) |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1259 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1260 |
matches := matches asSortedCollection. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1261 |
isMatchString ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1262 |
best := searchName. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1263 |
] ifFalse:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1264 |
best := matches longestCommonPrefix. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1265 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1266 |
^ 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
|
1267 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1268 |
" |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1269 |
Smalltalk globalnameCompletion:'Arr' |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1270 |
Smalltalk globalnameCompletion:'Arra' |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1271 |
Smalltalk globalnameCompletion:'arra' |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1272 |
Smalltalk globalnameCompletion:'*rray' |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1273 |
" |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1274 |
|
2975 | 1275 |
"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
|
1276 |
! |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1277 |
|
2975 | 1278 |
methodProtocolCompletion:aPartialProtocolName inEnvironment:anEnvironment |
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1279 |
"given a partial method protocol 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
|
1280 |
2 entries: 1st: the best (longest) match |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1281 |
2nd: collection consisting of matching protocols" |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1282 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1283 |
|matches best lcName| |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1284 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1285 |
matches := IdentitySet new. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1286 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1287 |
"/ search for exact match |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1288 |
anEnvironment allClassesDo:[:aClass | |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1289 |
aClass instAndClassSelectorsAndMethodsDo:[:aSelector :aMethod | |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1290 |
|protocol| |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1291 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1292 |
protocol := aMethod category. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1293 |
(protocol notNil and:[protocol startsWith:aPartialProtocolName]) ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1294 |
matches add:protocol |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1295 |
] |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1296 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1297 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1298 |
matches isEmpty ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1299 |
"/ search for case-ignoring match |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1300 |
lcName := aPartialProtocolName asLowercase. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1301 |
anEnvironment allClassesDo:[:aClass | |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1302 |
aClass instAndClassSelectorsAndMethodsDo:[:aSelector :aMethod | |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1303 |
|protocol| |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1304 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1305 |
protocol := aMethod category. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1306 |
(protocol asLowercase startsWith:lcName) ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1307 |
matches add:protocol |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1308 |
] |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1309 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1310 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1311 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1312 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1313 |
matches isEmpty ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1314 |
^ Array with:aPartialProtocolName with:(Array with:aPartialProtocolName) |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1315 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1316 |
matches size == 1 ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1317 |
^ Array with:matches first with:(matches asArray) |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1318 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1319 |
matches := matches asSortedCollection. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1320 |
best := matches longestCommonPrefix. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1321 |
^ 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
|
1322 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1323 |
" |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1324 |
Smalltalk methodProtocolCompletion:'doc' |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1325 |
Smalltalk methodProtocolCompletion:'docu' |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1326 |
Smalltalk methodProtocolCompletion:'documenta' |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1327 |
" |
2975 | 1328 |
|
1329 |
"Created: / 10-08-2006 / 13:05:27 / cg" |
|
1330 |
! |
|
1331 |
||
1332 |
nameSpaceCompletion:aPartialClassName inEnvironment:anEnvironment |
|
1333 |
"given a partial name, return an array consisting of |
|
1334 |
2 entries: 1st: the best (longest) match |
|
1335 |
2nd: collection consisting of matching names" |
|
1336 |
||
1337 |
^ self |
|
1338 |
classnameCompletion:aPartialClassName |
|
1339 |
filter:[:cls | cls isNameSpace] |
|
1340 |
inEnvironment:anEnvironment |
|
1341 |
||
1342 |
" |
|
1343 |
DoWhatIMeanSupport nameSpaceCompletion:'To' inEnvironment:Smalltalk |
|
1344 |
" |
|
1345 |
||
1346 |
"Created: / 10-08-2006 / 13:02:16 / cg" |
|
1347 |
! |
|
1348 |
||
1349 |
packageCompletion:aPartialPackage inEnvironment:anEnvironment |
|
1350 |
"given a partial package name, return an array consisting of |
|
1351 |
2 entries: 1st: the best (longest) match |
|
1352 |
2nd: collection consisting of matching packages" |
|
1353 |
||
1354 |
|matches best lcName| |
|
1355 |
||
1356 |
matches := IdentitySet new. |
|
1357 |
||
1358 |
"/ search for exact match |
|
1359 |
anEnvironment allClassesDo:[:aClass | |
|
1360 |
|package| |
|
1361 |
||
1362 |
package := aClass package. |
|
1363 |
(package notNil and:[package startsWith:aPartialPackage]) ifTrue:[ |
|
1364 |
matches add:package |
|
1365 |
] |
|
1366 |
]. |
|
1367 |
matches isEmpty ifTrue:[ |
|
1368 |
"/ search for case-ignoring match |
|
1369 |
lcName := aPartialPackage asLowercase. |
|
1370 |
anEnvironment allClassesDo:[:aClass | |
|
1371 |
|package| |
|
1372 |
||
1373 |
package := aClass package. |
|
1374 |
(package notNil and:[package asLowercase startsWith:lcName]) ifTrue:[ |
|
1375 |
matches add:package |
|
1376 |
]. |
|
1377 |
]. |
|
1378 |
]. |
|
1379 |
||
1380 |
matches isEmpty ifTrue:[ |
|
1381 |
^ Array with:aPartialPackage with:(Array with:aPartialPackage) |
|
1382 |
]. |
|
1383 |
matches size == 1 ifTrue:[ |
|
1384 |
^ Array with:matches first with:(matches asArray) |
|
1385 |
]. |
|
1386 |
matches := matches asSortedCollection. |
|
1387 |
best := matches longestCommonPrefix. |
|
1388 |
^ Array with:best with:matches asArray |
|
1389 |
||
1390 |
" |
|
1391 |
DoWhatIMeanSupport packageCompletion:'stx:' inEnvironment:Smalltalk |
|
1392 |
DoWhatIMeanSupport packageCompletion:'stx:libw' inEnvironment:Smalltalk |
|
1393 |
" |
|
1394 |
||
1395 |
"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
|
1396 |
! |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1397 |
|
2977 | 1398 |
packageNameEntryCompletionBlock |
1399 |
"this block can be used in a dialog to perform className completion" |
|
1400 |
||
1401 |
^ self entryCompletionBlockFor:#'packageCompletion:inEnvironment:' |
|
1402 |
||
1403 |
"Created: / 10-08-2006 / 13:22:31 / cg" |
|
1404 |
! |
|
1405 |
||
2661
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1406 |
selectorCompletion:aPartialSymbolName inEnvironment:anEnvironment |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1407 |
"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
|
1408 |
2 entries: 1st: the longest match |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1409 |
2nd: collection consisting of matching implemented selectors" |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1410 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1411 |
|matches best lcSym| |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1412 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1413 |
matches := IdentitySet new. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1414 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1415 |
"/ search for exact match |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1416 |
anEnvironment allClassesDo:[:aClass | |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1417 |
aClass instAndClassSelectorsAndMethodsDo:[:aSelector :aMethod | |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1418 |
(aSelector startsWith:aPartialSymbolName) ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1419 |
matches add:aSelector |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1420 |
] |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1421 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1422 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1423 |
matches isEmpty ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1424 |
"/ search for case-ignoring match |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1425 |
lcSym := aPartialSymbolName asLowercase. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1426 |
anEnvironment allClassesDo:[:aClass | |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1427 |
aClass instAndClassSelectorsAndMethodsDo:[:aSelector :aMethod | |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1428 |
(aSelector asLowercase startsWith:lcSym) ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1429 |
matches add:aSelector |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1430 |
] |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1431 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1432 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1433 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1434 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1435 |
matches isEmpty ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1436 |
^ Array with:aPartialSymbolName with:(Array with:aPartialSymbolName) |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1437 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1438 |
matches size == 1 ifTrue:[ |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1439 |
^ Array with:matches first with:(matches asArray) |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1440 |
]. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1441 |
matches := matches asSortedCollection. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1442 |
best := matches longestCommonPrefix. |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1443 |
^ 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
|
1444 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1445 |
" |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1446 |
Smalltalk selectorCompletion:'at:p' |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1447 |
Smalltalk selectorCompletion:'nextP' |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1448 |
Smalltalk selectorCompletion:'nextp' |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1449 |
" |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1450 |
|
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1451 |
"Modified: / 7.6.1996 / 08:44:33 / stefan" |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1452 |
"Modified: / 14.6.1998 / 15:54:03 / cg" |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1453 |
! ! |
f68913f2facf
moved all input completion methods from Smalltalk to here.
Claus Gittinger <cg@exept.de>
parents:
2560
diff
changeset
|
1454 |
|
2376 | 1455 |
!DoWhatIMeanSupport class methodsFor:'rename support'! |
1456 |
||
1457 |
goodRenameDefaultFor:oldName lastOld:lastOldName lastNew:lastNewName |
|
2513 | 1458 |
"generate a reasonable default for a rename operation. |
1459 |
(used for rename category etc.)" |
|
2468 | 1460 |
|
2559 | 1461 |
|prefix suffix lastNewSize lastOldSize left right inserted deleted| |
2376 | 1462 |
|
1463 |
lastNewName isNil ifTrue:[ ^ nil]. |
|
1464 |
||
1465 |
lastNewSize := lastNewName size. |
|
1466 |
lastOldSize := lastOldName size. |
|
1467 |
||
1468 |
(lastNewName endsWith:lastOldName) ifTrue:[ |
|
2514 | 1469 |
"last rename was |
1470 |
'foo' -> 'Xfoo' |
|
1471 |
then, a good default for |
|
1472 |
'bar' would be 'Xbar' |
|
1473 |
" |
|
2376 | 1474 |
prefix := lastNewName copyTo:(lastNewSize - lastOldSize). |
1475 |
^ (prefix , oldName). |
|
1476 |
]. |
|
1477 |
(lastOldName endsWith:lastNewName) ifTrue:[ |
|
2514 | 1478 |
"last rename was |
1479 |
'Xfoo' -> 'foo' |
|
1480 |
then, a good default for |
|
1481 |
'Xbar' would be 'bar' |
|
1482 |
" |
|
2376 | 1483 |
prefix := lastOldName copyTo:(lastOldSize - lastNewSize). |
2514 | 1484 |
(oldName startsWith:prefix) ifTrue:[ |
1485 |
^ (oldName copyFrom:prefix size+1). |
|
1486 |
] |
|
1487 |
]. |
|
1488 |
(lastOldName asLowercase = lastNewName asLowercase) ifTrue:[ |
|
1489 |
(lastOldName first ~= lastNewName first) ifTrue:[ |
|
1490 |
(lastOldName first isLowercase = oldName first isLowercase) ifTrue:[ |
|
1491 |
"last rename was |
|
1492 |
'xfoo' -> 'Xfoo' |
|
1493 |
then, a good default for |
|
1494 |
'xbar' would be 'Xbar' |
|
1495 |
" |
|
1496 |
lastOldName first isLowercase ifTrue:[ |
|
1497 |
^ oldName first asUppercase asString , (oldName copyFrom:2). |
|
1498 |
] ifFalse:[ |
|
1499 |
^ oldName first asLowercase asString , (oldName copyFrom:2). |
|
1500 |
] |
|
1501 |
] |
|
1502 |
]. |
|
2376 | 1503 |
]. |
1504 |
(lastOldName withoutSeparators = lastNewName) ifTrue:[ |
|
2514 | 1505 |
"last rename was |
1506 |
' foo ' -> 'foo' |
|
1507 |
then, a good default for |
|
1508 |
' bar ' would be 'bar' |
|
1509 |
" |
|
2376 | 1510 |
^ oldName withoutSeparators. |
1511 |
]. |
|
1512 |
(lastNewName startsWith:lastOldName) ifTrue:[ |
|
2557 | 1513 |
"last rename was |
1514 |
'foo' -> 'fooX' |
|
1515 |
then, a good default for |
|
1516 |
'bar' would be 'barX' |
|
1517 |
" |
|
2376 | 1518 |
suffix := lastNewName copyLast:(lastNewSize - lastOldSize). |
1519 |
^ (oldName , suffix). |
|
1520 |
]. |
|
1521 |
(lastOldName startsWith:lastNewName) ifTrue:[ |
|
2557 | 1522 |
"last rename was |
1523 |
'fooX' -> 'foo' |
|
1524 |
then, a good default for |
|
1525 |
'barX' would be 'bar' |
|
1526 |
" |
|
2376 | 1527 |
suffix := lastOldName copyLast:(lastOldSize - lastNewSize). |
1528 |
(oldName endsWith:suffix) ifTrue:[ |
|
1529 |
^ (oldName copyWithoutLast:suffix size). |
|
1530 |
] |
|
1531 |
]. |
|
2558 | 1532 |
|
2557 | 1533 |
prefix := lastOldName commonPrefixWith:lastNewName. |
1534 |
suffix := lastOldName commonSuffixWith:lastNewName. |
|
2559 | 1535 |
|
2558 | 1536 |
(prefix size > 0) ifTrue:[ |
1537 |
(suffix size > 0) ifTrue:[ |
|
2559 | 1538 |
|
1539 |
prefix := prefix copyTo:(((lastNewName size - suffix size) min:(lastOldName size - suffix size)) min:prefix size). |
|
1540 |
||
2558 | 1541 |
"last rename was |
1542 |
'fooR' -> 'fooXR' |
|
1543 |
then, a good default for |
|
1544 |
'barR' would be 'barXR' |
|
1545 |
" |
|
1546 |
left := lastOldName copyTo:prefix size. |
|
1547 |
right := lastOldName copyLast:suffix size. |
|
2559 | 1548 |
lastNewSize > lastOldSize ifTrue:[ |
1549 |
inserted := (lastNewName copyFrom:(left size + 1)) copyWithoutLast:(right size). |
|
1550 |
inserted size > 0 ifTrue:[ |
|
3532 | 1551 |
(oldName startsWith:prefix) ifTrue:[ |
1552 |
^ (oldName copyTo:prefix size) , inserted , (oldName copyFrom:prefix size + 1) |
|
1553 |
]. |
|
2559 | 1554 |
]. |
1555 |
]. |
|
1556 |
(oldName endsWith:suffix) ifTrue:[ |
|
1557 |
deleted := (lastOldName copyFrom:(prefix size + 1)) copyWithoutLast:(suffix size). |
|
1558 |
((oldName copyFrom:oldName size-suffix size-deleted size + 1) copyTo:deleted size) = deleted ifTrue:[ |
|
1559 |
"last rename was |
|
1560 |
'fooXR' -> 'fooR' |
|
1561 |
then, a good default for |
|
1562 |
'barXS' would be 'barS' |
|
1563 |
" |
|
1564 |
^ (oldName copyTo:oldName size-suffix size-deleted size) , suffix |
|
1565 |
] |
|
1566 |
] |
|
2558 | 1567 |
]. |
1568 |
||
1569 |
(oldName endsWith:(lastOldName copyFrom:prefix size+1)) ifTrue:[ |
|
1570 |
"last rename was |
|
1571 |
'fooX' -> 'fooY' |
|
1572 |
then, a good default for |
|
1573 |
'barX' would be 'barY' |
|
1574 |
" |
|
1575 |
left := oldName copyWithoutLast:(lastOldName copyFrom:prefix size+1) size. |
|
1576 |
right := lastNewName copyFrom:prefix size+1. |
|
1577 |
^ left , right |
|
1578 |
] |
|
2557 | 1579 |
]. |
2376 | 1580 |
|
2382
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
1581 |
^ nil |
2557 | 1582 |
|
1583 |
" |
|
2558 | 1584 |
self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'fooXX' |
1585 |
self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'XXfoo' |
|
1586 |
||
1587 |
self goodRenameDefaultFor:'barXX' lastOld:'fooXX' lastNew:'foo' |
|
1588 |
self goodRenameDefaultFor:'XXbar' lastOld:'XXfoo' lastNew:'foo' |
|
1589 |
||
1590 |
self goodRenameDefaultFor:'barXX' lastOld:'fooXX' lastNew:'fooYY' |
|
1591 |
self goodRenameDefaultFor:'XXbar' lastOld:'XXfoo' lastNew:'foo' |
|
1592 |
||
2559 | 1593 |
self goodRenameDefaultFor:'bar2' lastOld:'foo1' lastNew:'foo01' |
1594 |
self goodRenameDefaultFor:'barXY' lastOld:'fooXY' lastNew:'fooY' |
|
2560 | 1595 |
self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'fXoo' |
1596 |
self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'fXXXoo' |
|
2559 | 1597 |
self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'foXXXo' |
1598 |
||
1599 |
self goodRenameDefaultFor:'bar001' lastOld:'foo001' lastNew:'foo002_001' |
|
2560 | 1600 |
self goodRenameDefaultFor:'CoastCore-CSFoo' lastOld:'CoastCore-CSBar' lastNew:'Coast-Core-CSBar' |
2557 | 1601 |
" |
2382
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
1602 |
! |
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
1603 |
|
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
1604 |
goodRenameDefaultForFile:oldName lastOld:lastOldName lastNew:lastNewName |
2513 | 1605 |
"generate a reasonable default for a file rename operation. |
1606 |
(Try to rename multiple files in the new fileBrowser, |
|
1607 |
to see what this is doing)" |
|
2468 | 1608 |
|
2382
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
1609 |
|prefix suffix t |
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
1610 |
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
|
1611 |
lastRemoved lastInserted default| |
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
1612 |
|
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
1613 |
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
|
1614 |
default notNil ifTrue:[ ^ default]. |
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
1615 |
|
3135
7ad9ff29225e
changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents:
2977
diff
changeset
|
1616 |
lastOldWOSuffix := lastOldName asFilename nameWithoutSuffix. |
7ad9ff29225e
changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents:
2977
diff
changeset
|
1617 |
lastNewWOSuffix := lastNewName asFilename nameWithoutSuffix. |
7ad9ff29225e
changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents:
2977
diff
changeset
|
1618 |
oldWOSuffix := oldName asFilename nameWithoutSuffix. |
2376 | 1619 |
|
2434 | 1620 |
"/ suffix change ? |
1621 |
lastOldWOSuffix = lastNewWOSuffix ifTrue:[ |
|
1622 |
lastOldName asFilename suffix ~= lastNewName asFilename suffix ifTrue:[ |
|
1623 |
^ (oldName asFilename withSuffix:(lastNewName asFilename suffix)) pathName |
|
1624 |
]. |
|
1625 |
]. |
|
1626 |
||
2553 | 1627 |
default := self goodRenameDefaultFor:oldWOSuffix lastOld:lastOldWOSuffix lastNew:lastNewWOSuffix. |
1628 |
default notNil ifTrue:[ |
|
1629 |
lastOldRest := lastOldName copyFrom:lastOldWOSuffix size + 1. |
|
1630 |
lastNewRest := lastNewName copyFrom:lastNewWOSuffix size + 1. |
|
1631 |
oldRest := oldName copyFrom:oldWOSuffix size + 1. |
|
1632 |
||
1633 |
^ default , lastNewRest |
|
1634 |
]. |
|
1635 |
||
2376 | 1636 |
prefix := lastOldWOSuffix commonPrefixWith:oldWOSuffix. |
1637 |
(lastNewWOSuffix startsWith:prefix) ifTrue:[ |
|
1638 |
lastOldRest := lastOldWOSuffix copyFrom:prefix size + 1. |
|
1639 |
lastNewRest := lastNewWOSuffix copyFrom:prefix size + 1. |
|
1640 |
oldRest := oldWOSuffix copyFrom:prefix size + 1. |
|
1641 |
||
1642 |
(lastNewRest endsWith:lastOldRest) ifTrue:[ |
|
1643 |
t := lastNewRest copyWithoutLast:lastOldRest size. |
|
1644 |
^ ((prefix , t , oldRest) asFilename withSuffix:oldName asFilename suffix) name |
|
1645 |
]. |
|
1646 |
]. |
|
1647 |
||
1648 |
suffix := lastOldWOSuffix commonSuffixWith:lastNewWOSuffix. |
|
1649 |
suffix size > 0 ifTrue:[ |
|
1650 |
"/ last change changed something at the beginning |
|
1651 |
prefix := oldWOSuffix commonPrefixWith:lastOldWOSuffix. |
|
1652 |
prefix size > 0 ifTrue:[ |
|
1653 |
"/ this name starts with the same characters |
|
1654 |
lastRemoved := lastOldWOSuffix copyWithoutLast:suffix size. |
|
1655 |
lastInserted := lastNewWOSuffix copyWithoutLast:suffix size. |
|
1656 |
(lastRemoved startsWith:lastInserted) ifTrue:[ |
|
1657 |
oldWOSuffix size >= lastInserted size ifTrue:[ |
|
1658 |
^ (oldWOSuffix copyTo:lastInserted size) , (oldName copyFrom:lastRemoved size + 1) |
|
1659 |
] |
|
1660 |
]. |
|
1661 |
^ lastInserted , (oldName copyFrom:lastRemoved size + 1) |
|
1662 |
]. |
|
1663 |
]. |
|
1664 |
||
1665 |
^ nil |
|
3135
7ad9ff29225e
changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents:
2977
diff
changeset
|
1666 |
|
7ad9ff29225e
changed #classCategoryLoadFromRepository
Claus Gittinger <cg@exept.de>
parents:
2977
diff
changeset
|
1667 |
"Modified: / 07-11-2006 / 13:58:39 / cg" |
2376 | 1668 |
! ! |
1669 |
||
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1670 |
!DoWhatIMeanSupport class methodsFor:'typing distance'! |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1671 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1672 |
isKey:k1 nextTo:k2 |
2774 | 1673 |
"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
|
1674 |
This is used to specially priorize plausible typing errors of adjacent keys. |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
1675 |
CAVEAT: hard coded us- and german keyboards here." |
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1676 |
|
3316 | 1677 |
^ 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
|
1678 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1679 |
" |
3299
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
1680 |
self isKey:$a nextTo:$a |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
1681 |
self isKey:$a nextTo:$s |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
1682 |
self isKey:$a nextTo:$q |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
1683 |
self isKey:$a nextTo:$w |
1cd4b22434a6
code completion stuff moved to here (for reuse)
Claus Gittinger <cg@exept.de>
parents:
3198
diff
changeset
|
1684 |
self isKey:$a nextTo:$z |
2517 | 1685 |
self isKey:$a nextTo:$x |
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1686 |
" |
3316 | 1687 |
|
1688 |
"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
|
1689 |
! |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1690 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1691 |
isKey:k1 nextTo:k2 onKeyboard:keys |
2774 | 1692 |
"return true, if k1 and k2 are adjacent keys on the keyboard defined by keys" |
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1693 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1694 |
|row1 row2 col1 col2| |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1695 |
|
2774 | 1696 |
row1 := keys findFirst:[:eachRow | col1 := eachRow indexOf:k1. col1 ~~ 0]. |
2517 | 1697 |
row1 == 0 ifTrue:[^ false]. |
2774 | 1698 |
row2 := keys findFirst:[:eachRow | col2 := eachRow indexOf:k2. col2 ~~ 0]. |
2517 | 1699 |
row2 == 0 ifTrue:[^ false]. |
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1700 |
|
2774 | 1701 |
^ (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
|
1702 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1703 |
" |
2774 | 1704 |
self isKey:$a nextTo:$q |
2517 | 1705 |
self isKey:$a nextTo:$x |
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1706 |
" |
3316 | 1707 |
! |
1708 |
||
1709 |
keyboard |
|
1710 |
"the keyboard layout (to find possible typing errors)" |
|
1711 |
||
1712 |
|lang| |
|
1713 |
||
1714 |
lang := UserPreferences current language. |
|
1715 |
lang == #de ifTrue:[ |
|
1716 |
^ #( |
|
1717 |
'1234567890-' |
|
1718 |
'*qwertzuiop' |
|
1719 |
'**asdfghjkl:' |
|
1720 |
'***yxcvbnm' ). |
|
1721 |
]. |
|
1722 |
||
1723 |
lang == #fr ifTrue:[ |
|
1724 |
^ #( |
|
1725 |
'1234567890' |
|
1726 |
'*azertyuiop' |
|
1727 |
'**qsdfghjklm' |
|
1728 |
'***wxcvbn,' ). |
|
1729 |
]. |
|
1730 |
||
1731 |
^ #( |
|
1732 |
'1234567890-' |
|
1733 |
'*qwertyuiop' |
|
1734 |
'**asdfghjkl:' |
|
1735 |
'***zxcvbnm' ). |
|
1736 |
||
1737 |
" |
|
1738 |
self keyboard |
|
1739 |
" |
|
1740 |
||
1741 |
"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
|
1742 |
! ! |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
1743 |
|
2376 | 1744 |
!DoWhatIMeanSupport class methodsFor:'documentation'! |
1745 |
||
1746 |
version |
|
3552
e631f2f7bb2a
code completion for symbol literals
Claus Gittinger <cg@exept.de>
parents:
3551
diff
changeset
|
1747 |
^ '$Header: /cvs/stx/stx/libwidg2/DoWhatIMeanSupport.st,v 1.43 2008-10-11 17:02:40 cg Exp $' |
2376 | 1748 |
! ! |