FindReferences() public method

Provides the list of references for a given filter
public FindReferences ( BaseFilter filter ) : List
filter BaseFilter
return List
        /// <summary>
        ///     Provides all the function calls related to this namespace
        /// </summary>
        /// <param name="system">The system in which the calls should be gathered</param>
        /// <param name="container">If provided, indicates that the calls should be limited to a given container</param>
        /// <returns></returns>
        public static List<AccessMode> getAccesses(EfsSystem system, IEnclosesNameSpaces container = null)
        {
            SortedSet<ProcedureOrFunctionCall> procedureCalls = new SortedSet<ProcedureOrFunctionCall>();
            SortedSet<AccessToVariable> accessesToVariables = new SortedSet<AccessToVariable>();
            foreach (Usage usage in system.FindReferences(IsCallableOrIsVariable.INSTANCE))
            {
                ModelElement target = (ModelElement) usage.Referenced;
                ModelElement source = usage.User;

                NameSpace sourceNameSpace = getCorrespondingNameSpace(source, container, true);
                NameSpace targetNameSpace = getCorrespondingNameSpace(target, container, false);

                if (IsCallable.Predicate(usage.Referenced))
                {
                    if (considerCall(usage, container, sourceNameSpace, targetNameSpace))
                    {
                        procedureCalls.Add(new ProcedureOrFunctionCall(sourceNameSpace, targetNameSpace,
                            (ICallable) target));
                    }
                }
                else
                {
                    // IsVariable(usage.Referenced)
                    if (considerVariableReference(usage, container, sourceNameSpace, targetNameSpace))
                    {
                        Usage.ModeEnum mode = (Usage.ModeEnum) usage.Mode;

                        // Find a corresponding access to variable (same source and target namespaces, and same variable
                        AccessToVariable otherAccess = null;
                        foreach (AccessToVariable access in accessesToVariables)
                        {
                            if (access.Target == usage.Referenced && access.Source == sourceNameSpace &&
                                access.Target == targetNameSpace)
                            {
                                otherAccess = access;
                                break;
                            }
                        }

                        if (otherAccess != null)
                        {
                            if (otherAccess.AccessMode != mode)
                            {
                                // Since the access mode is different, one of them is either Read or ReadWrite and the other is ReadWrite or Write.
                                // So, in any case, the resulting access mode is ReadWrite
                                accessesToVariables.Remove(otherAccess);
                                accessesToVariables.Add(new AccessToVariable(sourceNameSpace, targetNameSpace,
                                    (IVariable) target, Usage.ModeEnum.ReadAndWrite));
                            }
                            else
                            {
                                // Already exists, do nothing
                            }
                        }
                        else
                        {
                            // Does not already exists, insert it in the list
                            accessesToVariables.Add(new AccessToVariable(sourceNameSpace, targetNameSpace,
                                (IVariable) target, mode));
                        }
                    }
                }
            }

            // Build the results based on the intermediate results
            List<AccessMode> retVal = new List<AccessMode>();
            retVal.AddRange(procedureCalls);
            retVal.AddRange(accessesToVariables);

            return retVal;
        }