Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ CoASTHeuristicsResultSetBuilder class >> initializeMessagesHeuristic [
CoSuperMessageHeuristic new.
CoDependencyMessageHeuristics new .
CoTypedReceiverMessageHeuristic new .
CoInferredReceiverMessageHeuristic new.
CoInitializeInferencedMessageHeuristic new .
CoLiteralMessageHeuristic new .
CoGlobalVariableMessageHeuristic new .
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"
I ask the type inferencer for the type of that receiver expression, then propose selectors from the inferred type hierarchy.

"
Class {
#name : 'CoInferredReceiverMessageHeuristic',
#superclass : 'CoASTNodeFetcherHeuristic',
#category : 'HeuristicCompletion-Model-Heuristics',
#package : 'HeuristicCompletion-Model',
#tag : 'Heuristics'
}

{ #category : 'requests' }
CoInferredReceiverMessageHeuristic >> appliesForNode: aMessageNode inContext: aContext [

^ aMessageNode isMessage
and: [ aMessageNode receiver isMessage ]
]

{ #category : 'requests' }
CoInferredReceiverMessageHeuristic >> buildFetcherFor: aMessageNode inContext: aContext [

| receiverTypes fetcher |

receiverTypes := self
inferredTypesOf: aMessageNode receiver
inContext: aContext.

receiverTypes := receiverTypes select: [ :each |
self canCompleteMessagesFor: each ].

receiverTypes ifEmpty: [ ^ CoEmptyFetcher new ].

fetcher := CoEmptyFetcher new.

receiverTypes do: [ :each |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not get this code. We do a loop and we store into a variables so basically we get the last oen

fetcher := (self
newMessageInHierarchyFetcherForClass: each
inASTNode: aMessageNode), fetcher ].

^ fetcher
]

{ #category : 'requests' }
CoInferredReceiverMessageHeuristic >> canCompleteMessagesFor: aType [

^ aType notNil
and: [
(aType isKindOf: CoUnknownType) not
and: [ aType respondsTo: #selectorsDo ] ]
]

{ #category : 'requests' }
CoInferredReceiverMessageHeuristic >> inferredTypesOf: aReceiverNode inContext: aContext [

| inferer |

inferer := CoTypeInferencer new.
inferer receiverClass: (aContext completionClass ifNil: [ Object ]).

^ [
(aReceiverNode acceptVisitor: inferer) asSet asOrderedCollection
] on: Error do: [ :error |
"Completion must never break the editor. If inference fails,
let the next heuristic, usually CoUnknownMessageHeuristic, answer."
#() ]
]