|
|
@ -42,25 +42,38 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin |
|
|
|
public IEnumerable<ISymbol> Analyze(ISymbol analyzedSymbol, AnalyzerContext context) |
|
|
|
public IEnumerable<ISymbol> Analyze(ISymbol analyzedSymbol, AnalyzerContext context) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Debug.Assert(analyzedSymbol is IMethod); |
|
|
|
Debug.Assert(analyzedSymbol is IMethod); |
|
|
|
var scope = context.GetScopeOf((IEntity)analyzedSymbol); |
|
|
|
var analyzedMethod = (IMethod)analyzedSymbol; |
|
|
|
|
|
|
|
var mapping = context.Language |
|
|
|
|
|
|
|
.GetCodeMappingInfo(analyzedMethod.ParentModule.PEFile, |
|
|
|
|
|
|
|
analyzedMethod.DeclaringTypeDefinition.MetadataToken); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var parentMethod = mapping.GetParentMethod((MethodDefinitionHandle)analyzedMethod.MetadataToken); |
|
|
|
|
|
|
|
if (parentMethod != analyzedMethod.MetadataToken) |
|
|
|
|
|
|
|
yield return ((MetadataModule)analyzedMethod.ParentModule).GetDefinition(parentMethod); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var scope = context.GetScopeOf(analyzedMethod); |
|
|
|
foreach (var type in scope.GetTypesInScope(context.CancellationToken)) |
|
|
|
foreach (var type in scope.GetTypesInScope(context.CancellationToken)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var mappingInfo = context.Language.GetCodeMappingInfo(type.ParentModule.PEFile, type.MetadataToken); |
|
|
|
var parentModule = (MetadataModule)type.ParentModule; |
|
|
|
|
|
|
|
mapping = context.Language.GetCodeMappingInfo(parentModule.PEFile, type.MetadataToken); |
|
|
|
var methods = type.GetMembers(m => m is IMethod, Options).OfType<IMethod>(); |
|
|
|
var methods = type.GetMembers(m => m is IMethod, Options).OfType<IMethod>(); |
|
|
|
foreach (var method in methods) |
|
|
|
foreach (var method in methods) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (IsUsedInMethod((IMethod)analyzedSymbol, method, mappingInfo, context)) |
|
|
|
if (IsUsedInMethod((IMethod)analyzedSymbol, method, context)) |
|
|
|
yield return method; |
|
|
|
{ |
|
|
|
|
|
|
|
var parent = mapping.GetParentMethod((MethodDefinitionHandle)method.MetadataToken); |
|
|
|
|
|
|
|
yield return parentModule.GetDefinition(parent); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
foreach (var property in type.Properties) |
|
|
|
foreach (var property in type.Properties) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (property.CanGet && IsUsedInMethod((IMethod)analyzedSymbol, property.Getter, mappingInfo, context)) |
|
|
|
if (property.CanGet && IsUsedInMethod((IMethod)analyzedSymbol, property.Getter, context)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
yield return property; |
|
|
|
yield return property; |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
if (property.CanSet && IsUsedInMethod((IMethod)analyzedSymbol, property.Setter, mappingInfo, context)) |
|
|
|
if (property.CanSet && IsUsedInMethod((IMethod)analyzedSymbol, property.Setter, context)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
yield return property; |
|
|
|
yield return property; |
|
|
|
continue; |
|
|
|
continue; |
|
|
@ -69,17 +82,17 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin |
|
|
|
|
|
|
|
|
|
|
|
foreach (var @event in type.Events) |
|
|
|
foreach (var @event in type.Events) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (@event.CanAdd && IsUsedInMethod((IMethod)analyzedSymbol, @event.AddAccessor, mappingInfo, context)) |
|
|
|
if (@event.CanAdd && IsUsedInMethod((IMethod)analyzedSymbol, @event.AddAccessor, context)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
yield return @event; |
|
|
|
yield return @event; |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
if (@event.CanRemove && IsUsedInMethod((IMethod)analyzedSymbol, @event.RemoveAccessor, mappingInfo, context)) |
|
|
|
if (@event.CanRemove && IsUsedInMethod((IMethod)analyzedSymbol, @event.RemoveAccessor, context)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
yield return @event; |
|
|
|
yield return @event; |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
if (@event.CanInvoke && IsUsedInMethod((IMethod)analyzedSymbol, @event.InvokeAccessor, mappingInfo, context)) |
|
|
|
if (@event.CanInvoke && IsUsedInMethod((IMethod)analyzedSymbol, @event.InvokeAccessor, context)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
yield return @event; |
|
|
|
yield return @event; |
|
|
|
continue; |
|
|
|
continue; |
|
|
@ -89,7 +102,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool IsUsedInMethod(IMethod analyzedEntity, IMethod method, CodeMappingInfo mappingInfo, AnalyzerContext context) |
|
|
|
bool IsUsedInMethod(IMethod analyzedEntity, IMethod method, AnalyzerContext context) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return ScanMethodBody(analyzedEntity, method, context.GetMethodBody(method)); |
|
|
|
return ScanMethodBody(analyzedEntity, method, context.GetMethodBody(method)); |
|
|
|
} |
|
|
|
} |
|
|
|