提交 1743bab9 编写于 作者: C CyrusNajmabadi

Provide an API to get unreferenced assembly identities obects from the...

Provide an API to get unreferenced assembly identities obects from the diagnostics reported about them.
上级 c08aec57
......@@ -1523,6 +1523,9 @@ private MethodSymbol FindEntryPoint(CancellationToken cancellationToken, out Imm
}
}
internal override ImmutableArray<int> UnreferencedAssemblyIdentityDiagnosticCodes { get; }
= ImmutableArray.Create((int)ErrorCode.ERR_NoTypeDef);
internal class EntryPoint
{
public readonly MethodSymbol MethodSymbol;
......
......@@ -2668,5 +2668,44 @@ internal bool IsTypeMissing(WellKnownType type)
}
internal abstract bool IsIOperationFeatureEnabled();
/// <summary>
/// Given a <see cref="Diagnostic"/> reporting unreferenced <see cref="AssemblyIdentity"/>s, returns
/// the actual <see cref="AssemblyIdentity"/> instances that were not referenced.
/// </summary>
public ImmutableArray<AssemblyIdentity> GetUnreferencedAssemblyIdentities(Diagnostic diagnostic)
{
if (diagnostic == null)
{
throw new ArgumentNullException(nameof(diagnostic));
}
if (UnreferencedAssemblyIdentityDiagnosticCodes.Contains(diagnostic.Code))
{
return ExtractAssemblyIdenties(diagnostic);
}
return ImmutableArray<AssemblyIdentity>.Empty;
}
/// <summary>
/// For testing purposes.
/// </summary>
internal abstract ImmutableArray<int> UnreferencedAssemblyIdentityDiagnosticCodes { get; }
internal static ImmutableArray<AssemblyIdentity> ExtractAssemblyIdenties(Diagnostic diagnostic)
{
var builder = ArrayBuilder<AssemblyIdentity>.GetInstance();
foreach (var argument in diagnostic.Arguments)
{
if (argument is AssemblyIdentity id)
{
builder.Add(id);
}
}
return builder.ToImmutableAndFree();
}
}
}
\ No newline at end of file
......@@ -15,6 +15,7 @@ Microsoft.CodeAnalysis.Compilation.CreateTupleTypeSymbol(Microsoft.CodeAnalysis.
Microsoft.CodeAnalysis.Compilation.CreateTupleTypeSymbol(System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.ITypeSymbol> elementTypes, System.Collections.Immutable.ImmutableArray<string> elementNames = default(System.Collections.Immutable.ImmutableArray<string>), System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Location> elementLocations = default(System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Location>)) -> Microsoft.CodeAnalysis.INamedTypeSymbol
Microsoft.CodeAnalysis.Compilation.Emit(System.IO.Stream peStream, System.IO.Stream pdbStream = null, System.IO.Stream xmlDocumentationStream = null, System.IO.Stream win32Resources = null, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.ResourceDescription> manifestResources = null, Microsoft.CodeAnalysis.Emit.EmitOptions options = null, Microsoft.CodeAnalysis.IMethodSymbol debugEntryPoint = null, System.IO.Stream sourceLinkStream = null, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.EmbeddedText> embeddedTexts = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.Emit.EmitResult
Microsoft.CodeAnalysis.Compilation.Emit(System.IO.Stream peStream, System.IO.Stream pdbStream, System.IO.Stream xmlDocumentationStream, System.IO.Stream win32Resources, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.ResourceDescription> manifestResources, Microsoft.CodeAnalysis.Emit.EmitOptions options, Microsoft.CodeAnalysis.IMethodSymbol debugEntryPoint, System.Threading.CancellationToken cancellationToken) -> Microsoft.CodeAnalysis.Emit.EmitResult
Microsoft.CodeAnalysis.Compilation.GetUnreferencedAssemblyIdentities(Microsoft.CodeAnalysis.Diagnostic diagnostic) -> System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.AssemblyIdentity>
Microsoft.CodeAnalysis.CompilationOptions.WithConcurrentBuild(bool concurrent) -> Microsoft.CodeAnalysis.CompilationOptions
Microsoft.CodeAnalysis.CompilationOptions.WithCryptoKeyContainer(string cryptoKeyContainer) -> Microsoft.CodeAnalysis.CompilationOptions
Microsoft.CodeAnalysis.CompilationOptions.WithCryptoKeyFile(string cryptoKeyFile) -> Microsoft.CodeAnalysis.CompilationOptions
......
......@@ -2702,6 +2702,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Return If(IOperationFeatureFlag Is Nothing, False, options.Features.ContainsKey(IOperationFeatureFlag))
End Function
Friend Overrides ReadOnly Property UnreferencedAssemblyIdentityDiagnosticCodes As ImmutableArray(Of Integer) =
ImmutableArray.Create(Of Integer)(
ERRID.ERR_UnreferencedAssemblyEvent3,
ERRID.ERR_UnreferencedModuleBase3,
ERRID.ERR_UnreferencedModuleImplements3,
ERRID.ERR_UnreferencedAssembly3)
#End Region
Private Class SymbolSearcher
......
......@@ -97,6 +97,19 @@ public static TCompilation VerifyDiagnostics<TCompilation>(this TCompilation c,
{
var diagnostics = c.GetDiagnostics();
diagnostics.Verify(expected);
// At this point we've verified that the expected and actual diagnostics are the same.
var unreferencedAssemblyDiagnosticIds = c.UnreferencedAssemblyIdentityDiagnosticCodes;
foreach (var diagnostic in diagnostics)
{
if (unreferencedAssemblyDiagnosticIds.Contains(diagnostic.Code))
{
// Ensure that this diagnostic contains at least one assembly id.
var assemblyIds = c.GetUnreferencedAssemblyIdentities(diagnostic);
Assert.True(assemblyIds.Length > 0);
}
}
return c;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册