forked from pharo-project/pharo
/
NECSelectorEntry.class.st
108 lines (97 loc) · 3.03 KB
/
NECSelectorEntry.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
"
I represent a selector
"
Class {
#name : #NECSelectorEntry,
#superclass : #NECEntry,
#category : #'NECompletion-Model'
}
{ #category : #'ui related' }
NECSelectorEntry >> browseWith: anECContext [
"If there's a corresponding class, search for the method there,
otherwise search for the method in the system."
self flag: #SmalltalkReferences. "Reference to Smalltalk tools"
(self guessTypeWith: anECContext)
ifNotNil: [ :clazz|
Smalltalk tools browser openOnClass: clazz.
^ true ].
^ self
findMethodWith: anECContext
do: [ :class :method |
Smalltalk tools browser
openOnClass: class
selector: method selector.
true ]
ifAbsent: [ :selector |
SystemNavigation new
browseAllImplementorsOf: selector.
true ]
]
{ #category : #'detail information' }
NECSelectorEntry >> createDescriptionWith: anECContext [
"Creates description either from looking up the method in a class,
or in the system."
(self guessTypeWith: anECContext)
ifNotNil: [ :clazz|
^ NECEntryDescription
label: self label
title: clazz printString
description: clazz comment ].
^ self
findMethodWith: anECContext
do: [:clazz :method |
self
methodSourceDescription: clazz
method: method ]
ifAbsent: [:selector | self implementorsDescription: selector]
]
{ #category : #private }
NECSelectorEntry >> findMethodWith: anECContext do: foundBlock ifAbsent: notfoundBlock [
| theClass result implementors |
theClass := anECContext model theClass.
result := theClass
ifNil: [implementors := self systemNavigation allImplementorsOf: contents.
implementors size == 1
ifTrue: [| ref |
ref := implementors first.
ref realClass lookupSelector: ref selector]
ifFalse: [^ notfoundBlock value: contents]]
ifNotNil: [self lookupSelector: contents class: theClass].
^ foundBlock value: result first value: result second
]
{ #category : #private }
NECSelectorEntry >> implementorsDescription: aSymbol [
| implementors output |
output := WriteStream on: String new.
implementors := self systemNavigation allImplementorsOf: aSymbol.
implementors isEmpty ifTrue:
[ ^ NECEntryDescription
label: 'symbol'
title: '(no implementors)'
description: 'This is just symbol.' ].
implementors do: [ :each |
output
nextPutAll: each className printString;
cr ].
^ NECEntryDescription
label: self label
title: '(Implementors)'
description: output contents
]
{ #category : #accessing }
NECSelectorEntry >> label [
"I return whether the variable is a class or a method."
^ (self guessTypeWith: nil) ifNil:[ 'method' ] ifNotNil: [ 'class' ].
]
{ #category : #private }
NECSelectorEntry >> methodSourceDescription: aClass method: aCompiledMethod [
"I return if it's a class or a method, its class name, and the implementation."
| styler styledText |
styler := SHRBTextStyler new.
styler classOrMetaClass: aClass.
styledText := styler styledTextFor: (aCompiledMethod sourceCode) asText.
^ NECEntryDescription
label: self label
title: aClass printString
description: styledText
]