public List < ? extends ILinkingCandidate > getLinkingCandidates ( SarlCastedExpression cast ) { // Prepare the type resolver. final StackedResolvedTypes demandComputedTypes = pushTypes ( ) ; final AbstractTypeComputationState forked = withNonVoidExpectation ( demandComputedTypes ) ; final ForwardingResolvedTypes demandResolvedTypes = new ForwardingResolvedTypes ( ) { @ Override protected IResolvedTypes delegate ( ) { return forked . getResolvedTypes ( ) ; } @ Override public LightweightTypeReference getActualType ( XExpression expression ) { final LightweightTypeReference type = super . getActualType ( expression ) ; if ( type == null ) { final ITypeComputationResult result = forked . computeTypes ( expression ) ; return result . getActualExpressionType ( ) ; } return type ; } } ; // Create the scope final IScope scope = getCastScopeSession ( ) . getScope ( cast , // Must be the feature of the AbstractFeatureCall in order to enable the scoping for a function call. //XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, SarlPackage . Literals . SARL_CASTED_EXPRESSION__FEATURE , demandResolvedTypes ) ; // Search for the features into the scope final LightweightTypeReference targetType = getReferenceOwner ( ) . toLightweightTypeReference ( cast . getType ( ) ) ; final List < ILinkingCandidate > resultList = Lists . newArrayList ( ) ; final LightweightTypeReference expressionType = getStackedResolvedTypes ( ) . getActualType ( cast . getTarget ( ) ) ; final ISelector validator = this . candidateValidator . prepare ( getParent ( ) , targetType , expressionType ) ; // FIXME: The call to getAllElements() is not efficient; find another way in order to be faster. for ( final IEObjectDescription description : scope . getAllElements ( ) ) { final IIdentifiableElementDescription idesc = toIdentifiableDescription ( description ) ; if ( validator . isCastOperatorCandidate ( idesc ) ) { final ExpressionAwareStackedResolvedTypes descriptionResolvedTypes = pushTypes ( cast ) ; final ExpressionTypeComputationState descriptionState = createExpressionComputationState ( cast , descriptionResolvedTypes ) ; final ILinkingCandidate candidate = createCandidate ( cast , descriptionState , idesc ) ; if ( candidate != null ) { resultList . add ( candidate ) ; } } } return resultList ; }
Compute the best candidates for the feature behind the cast operator .