|
|
@ -21,6 +21,7 @@ using System.Collections.Generic; |
|
|
|
using System.Diagnostics; |
|
|
|
using System.Diagnostics; |
|
|
|
using System.Linq; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading; |
|
|
|
|
|
|
|
using ICSharpCode.NRefactory.CSharp; |
|
|
|
using ICSharpCode.NRefactory.CSharp.Refactoring; |
|
|
|
using ICSharpCode.NRefactory.CSharp.Refactoring; |
|
|
|
using ICSharpCode.NRefactory.CSharp.TypeSystem; |
|
|
|
using ICSharpCode.NRefactory.CSharp.TypeSystem; |
|
|
|
using ICSharpCode.NRefactory.Semantics; |
|
|
|
using ICSharpCode.NRefactory.Semantics; |
|
|
@ -220,16 +221,24 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver |
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region GetSearchScopes
|
|
|
|
#region GetSearchScopes
|
|
|
|
public IList<IFindReferenceSearchScope> GetSearchScopes(IEntity entity) |
|
|
|
public IList<IFindReferenceSearchScope> GetSearchScopes(ISymbol symbol) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (symbol == null) |
|
|
|
|
|
|
|
throw new ArgumentNullException("symbol"); |
|
|
|
|
|
|
|
switch (symbol.SymbolKind) { |
|
|
|
|
|
|
|
case SymbolKind.Namespace: |
|
|
|
|
|
|
|
return new[] { GetSearchScopeForNamespace((INamespace)symbol) }; |
|
|
|
|
|
|
|
case SymbolKind.TypeParameter: |
|
|
|
|
|
|
|
return new[] { GetSearchScopeForTypeParameter((ITypeParameter)symbol) }; |
|
|
|
|
|
|
|
// TODO: IVariable etc.
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
IEntity entity = symbol as IEntity; |
|
|
|
if (entity == null) |
|
|
|
if (entity == null) |
|
|
|
throw new ArgumentNullException("entity"); |
|
|
|
throw new NotSupportedException("Unsupported symbol type"); |
|
|
|
if (entity is IMember) |
|
|
|
if (entity is IMember) |
|
|
|
entity = NormalizeMember((IMember)entity); |
|
|
|
entity = NormalizeMember((IMember)entity); |
|
|
|
Accessibility effectiveAccessibility = GetEffectiveAccessibility(entity); |
|
|
|
Accessibility effectiveAccessibility = GetEffectiveAccessibility(entity); |
|
|
|
ITypeDefinition topLevelTypeDefinition = entity.DeclaringTypeDefinition; |
|
|
|
var topLevelTypeDefinition = GetTopLevelTypeDefinition(entity); |
|
|
|
while (topLevelTypeDefinition != null && topLevelTypeDefinition.DeclaringTypeDefinition != null) |
|
|
|
|
|
|
|
topLevelTypeDefinition = topLevelTypeDefinition.DeclaringTypeDefinition; |
|
|
|
|
|
|
|
SearchScope scope; |
|
|
|
SearchScope scope; |
|
|
|
SearchScope additionalScope = null; |
|
|
|
SearchScope additionalScope = null; |
|
|
|
switch (entity.SymbolKind) { |
|
|
|
switch (entity.SymbolKind) { |
|
|
@ -289,13 +298,22 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public IList<IFindReferenceSearchScope> GetSearchScopes(INamespace ns) |
|
|
|
public IList<IFindReferenceSearchScope> GetSearchScopes(IEnumerable<ISymbol> symbols) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (ns == null) |
|
|
|
if (symbols == null) |
|
|
|
throw new ArgumentNullException("ns"); |
|
|
|
throw new ArgumentNullException("symbols"); |
|
|
|
return new[] { GetSearchScopeForNamespace(ns) }; |
|
|
|
return symbols.SelectMany(GetSearchScopes).ToList(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static ITypeDefinition GetTopLevelTypeDefinition(IEntity entity) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (entity == null) |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
ITypeDefinition topLevelTypeDefinition = entity.DeclaringTypeDefinition; |
|
|
|
|
|
|
|
while (topLevelTypeDefinition != null && topLevelTypeDefinition.DeclaringTypeDefinition != null) |
|
|
|
|
|
|
|
topLevelTypeDefinition = topLevelTypeDefinition.DeclaringTypeDefinition; |
|
|
|
|
|
|
|
return topLevelTypeDefinition; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region GetInterestingFileNames
|
|
|
|
#region GetInterestingFileNames
|
|
|
@ -360,6 +378,36 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver |
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region FindReferencesInFile
|
|
|
|
#region FindReferencesInFile
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Finds all references in the given file.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="searchScope">The search scope for which to look.</param>
|
|
|
|
|
|
|
|
/// <param name="resolver">AST resolver for the file to search in.</param>
|
|
|
|
|
|
|
|
/// <param name="callback">Callback used to report the references that were found.</param>
|
|
|
|
|
|
|
|
/// <param name="cancellationToken">CancellationToken that may be used to cancel the operation.</param>
|
|
|
|
|
|
|
|
public void FindReferencesInFile(IFindReferenceSearchScope searchScope, CSharpAstResolver resolver, |
|
|
|
|
|
|
|
FoundReferenceCallback callback, CancellationToken cancellationToken) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (resolver == null) |
|
|
|
|
|
|
|
throw new ArgumentNullException("resolver"); |
|
|
|
|
|
|
|
FindReferencesInFile(searchScope, resolver.UnresolvedFile, (SyntaxTree)resolver.RootNode, resolver.Compilation, callback, cancellationToken); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Finds all references in the given file.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="searchScope">The search scopes for which to look.</param>
|
|
|
|
|
|
|
|
/// <param name="resolver">AST resolver for the file to search in.</param>
|
|
|
|
|
|
|
|
/// <param name="callback">Callback used to report the references that were found.</param>
|
|
|
|
|
|
|
|
/// <param name="cancellationToken">CancellationToken that may be used to cancel the operation.</param>
|
|
|
|
|
|
|
|
public void FindReferencesInFile(IList<IFindReferenceSearchScope> searchScopes, CSharpAstResolver resolver, |
|
|
|
|
|
|
|
FoundReferenceCallback callback, CancellationToken cancellationToken) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (resolver == null) |
|
|
|
|
|
|
|
throw new ArgumentNullException("resolver"); |
|
|
|
|
|
|
|
FindReferencesInFile(searchScopes, resolver.UnresolvedFile, (SyntaxTree)resolver.RootNode, resolver.Compilation, callback, cancellationToken); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Finds all references in the given file.
|
|
|
|
/// Finds all references in the given file.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
@ -424,6 +472,14 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region RenameReferencesInFile
|
|
|
|
|
|
|
|
public void RenameReferencesInFile(IList<IFindReferenceSearchScope> searchScopes, string newName, CSharpAstResolver resolver, |
|
|
|
|
|
|
|
Action<RenameCallbackArguments> callback, Action<Error> errorCallback, CancellationToken cancellationToken) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
throw new NotImplementedException(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Find TypeDefinition References
|
|
|
|
#region Find TypeDefinition References
|
|
|
|
SearchScope FindTypeDefinitionReferences(ITypeDefinition typeDefinition, bool findTypeReferencesEvenIfAliased, out SearchScope additionalScope) |
|
|
|
SearchScope FindTypeDefinitionReferences(ITypeDefinition typeDefinition, bool findTypeReferencesEvenIfAliased, out SearchScope additionalScope) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -843,8 +899,8 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver |
|
|
|
var arr = rr as AwaitResolveResult; |
|
|
|
var arr = rr as AwaitResolveResult; |
|
|
|
if (arr != null) { |
|
|
|
if (arr != null) { |
|
|
|
return IsMatch(arr.GetAwaiterInvocation) |
|
|
|
return IsMatch(arr.GetAwaiterInvocation) |
|
|
|
|| (arr.GetResultMethod != null && findReferences.IsMemberMatch(method, arr.GetResultMethod, true)) |
|
|
|
|| (arr.GetResultMethod != null && findReferences.IsMemberMatch(method, arr.GetResultMethod, true)) |
|
|
|
|| (arr.OnCompletedMethod != null && findReferences.IsMemberMatch(method, arr.OnCompletedMethod, true)); |
|
|
|
|| (arr.OnCompletedMethod != null && findReferences.IsMemberMatch(method, arr.OnCompletedMethod, true)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
var mrr = rr as MemberResolveResult; |
|
|
|
var mrr = rr as MemberResolveResult; |
|
|
@ -1090,7 +1146,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver |
|
|
|
internal override bool IsMatch(ResolveResult rr) |
|
|
|
internal override bool IsMatch(ResolveResult rr) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ConversionResolveResult crr = rr as ConversionResolveResult; |
|
|
|
ConversionResolveResult crr = rr as ConversionResolveResult; |
|
|
|
return crr != null && crr.Conversion.IsUserDefined |
|
|
|
return crr != null && crr.Conversion.IsUserDefined |
|
|
|
&& findReferences.IsMemberMatch(op, crr.Conversion.Method, crr.Conversion.IsVirtualMethodLookup); |
|
|
|
&& findReferences.IsMemberMatch(op, crr.Conversion.Method, crr.Conversion.IsVirtualMethodLookup); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -1282,8 +1338,9 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver |
|
|
|
/// <param name="compilation">The compilation.</param>
|
|
|
|
/// <param name="compilation">The compilation.</param>
|
|
|
|
/// <param name="callback">Callback used to report the references that were found.</param>
|
|
|
|
/// <param name="callback">Callback used to report the references that were found.</param>
|
|
|
|
/// <param name="cancellationToken">Cancellation token that may be used to cancel the operation.</param>
|
|
|
|
/// <param name="cancellationToken">Cancellation token that may be used to cancel the operation.</param>
|
|
|
|
|
|
|
|
[Obsolete("Use GetSearchScopes(typeParameter) instead")] |
|
|
|
public void FindTypeParameterReferences(IType typeParameter, CSharpUnresolvedFile unresolvedFile, SyntaxTree syntaxTree, |
|
|
|
public void FindTypeParameterReferences(IType typeParameter, CSharpUnresolvedFile unresolvedFile, SyntaxTree syntaxTree, |
|
|
|
ICompilation compilation, FoundReferenceCallback callback, CancellationToken cancellationToken) |
|
|
|
ICompilation compilation, FoundReferenceCallback callback, CancellationToken cancellationToken) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (typeParameter == null) |
|
|
|
if (typeParameter == null) |
|
|
|
throw new ArgumentNullException("typeParameter"); |
|
|
|
throw new ArgumentNullException("typeParameter"); |
|
|
@ -1295,6 +1352,17 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver |
|
|
|
FindReferencesInFile(searchScope, unresolvedFile, syntaxTree, compilation, callback, cancellationToken); |
|
|
|
FindReferencesInFile(searchScope, unresolvedFile, syntaxTree, compilation, callback, cancellationToken); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SearchScope GetSearchScopeForTypeParameter(ITypeParameter tp) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var searchScope = new SearchScope(c => new FindTypeParameterReferencesNavigator(tp)); |
|
|
|
|
|
|
|
var compilationProvider = tp as ICompilationProvider; |
|
|
|
|
|
|
|
if (compilationProvider != null) |
|
|
|
|
|
|
|
searchScope.declarationCompilation = compilationProvider.Compilation; |
|
|
|
|
|
|
|
searchScope.topLevelTypeDefinition = GetTopLevelTypeDefinition(tp.Owner); |
|
|
|
|
|
|
|
searchScope.accessibility = Accessibility.Private; |
|
|
|
|
|
|
|
return searchScope; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class FindTypeParameterReferencesNavigator : FindReferenceNavigator |
|
|
|
class FindTypeParameterReferencesNavigator : FindReferenceNavigator |
|
|
|
{ |
|
|
|
{ |
|
|
|
readonly ITypeParameter typeParameter; |
|
|
|
readonly ITypeParameter typeParameter; |
|
|
@ -1322,14 +1390,14 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Find Namespace References
|
|
|
|
#region Find Namespace References
|
|
|
|
SearchScope GetSearchScopeForNamespace(INamespace ns) |
|
|
|
SearchScope GetSearchScopeForNamespace(INamespace ns) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var scope = new SearchScope ( |
|
|
|
var scope = new SearchScope ( |
|
|
|
delegate (ICompilation compilation) { |
|
|
|
delegate (ICompilation compilation) { |
|
|
|
return new FindNamespaceNavigator (ns); |
|
|
|
return new FindNamespaceNavigator (ns); |
|
|
|
} |
|
|
|
} |
|
|
|
); |
|
|
|
); |
|
|
|
return scope; |
|
|
|
return scope; |
|
|
|
} |
|
|
|
} |
|
|
|