/// <summary> /// Searches through the <see cref="IScope.DeclaredVariables"/> to see if any of them /// <see cref="Matches(IVariableDeclaration)">matches</see> /// </summary> /// <returns>An enumerable of matching variable declarations.</returns> public override IEnumerable <IVariableDeclaration> FindMatches() { IEnumerable <IVariableDeclaration> matchingVariables = Enumerable.Empty <IVariableDeclaration>(); if (CallingObject != null) { matchingVariables = from matchingType in CallingObject.FindMatchingTypes() from typeDefinition in matchingType.GetParentTypesAndSelf() from variable in typeDefinition.DeclaredVariables where Matches(variable) select variable; } else { var matches = from scope in ParentScopes from variable in scope.DeclaredVariables where Matches(variable) select variable; var parameterMatches = from method in ParentScope.GetParentScopesAndSelf <IMethodDefinition>() from parameter in method.Parameters where Matches(parameter) select parameter; var matchingParentVariables = from containingType in ParentScope.GetParentScopesAndSelf <ITypeDefinition>() from typeDefinition in containingType.GetParentTypes() from variable in typeDefinition.DeclaredVariables where Matches(variable) select variable; matchingVariables = matches.Concat(matchingParentVariables).Concat(parameterMatches); } return(matchingVariables); }
/// <summary> /// Finds matching <see cref="IMethodDefinition">method definitions</see> from the /// <see cref="IScope.GetParentScopes()"/> of this usage. Because method calls can also be /// to constructors and destructors, this will also search for matching types and then /// constructors within those types /// </summary> /// <returns>An enumerable of method definitions that match this method call</returns> public override IEnumerable <IMethodDefinition> FindMatches() { IEnumerable <IMethodDefinition> matchingMethods = Enumerable.Empty <IMethodDefinition>(); if (IsConstructor || IsDestructor) { IEnumerable <ITypeDefinition> typeDefinitions; if (this.Name == "this" || (this.Name == "base" && this.ProgrammingLanguage == Language.CSharp)) { typeDefinitions = TypeDefinition.GetTypeForKeyword(this); } else { ITypeUse tempTypeUse = new TypeUse() { Name = this.Name, ParentScope = this.ParentScope, }; tempTypeUse.AddAliases(this.Aliases); typeDefinitions = tempTypeUse.FindMatches(); } matchingMethods = from typeDefinition in typeDefinitions from method in typeDefinition.GetChildScopesWithId <IMethodDefinition>(typeDefinition.Name) where Matches(method) select method; } else if (CallingObject != null) { matchingMethods = from matchingType in CallingObject.FindMatchingTypes() from typeDefinition in matchingType.GetParentTypesAndSelf() from method in typeDefinition.GetChildScopesWithId <IMethodDefinition>(this.Name) where Matches(method) select method; } else { var matches = base.FindMatches(); var matchingTypeMethods = from containingType in ParentScope.GetParentScopesAndSelf <ITypeDefinition>() from typeDefinition in containingType.GetParentTypes() from method in typeDefinition.GetChildScopesWithId <IMethodDefinition>(this.Name) where Matches(method) select method; matchingMethods = matches.Concat(matchingTypeMethods); } foreach (var method in matchingMethods) { yield return(method); } }