-
Notifications
You must be signed in to change notification settings - Fork 745
/
ImportedSymbol.cs
72 lines (59 loc) · 2.67 KB
/
ImportedSymbol.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Bicep.Core.Diagnostics;
using Bicep.Core.Registry;
using Bicep.Core.Semantics.Metadata;
using Bicep.Core.Syntax;
using Bicep.Core.Workspaces;
namespace Bicep.Core.Semantics;
public abstract class ImportedSymbol : DeclaredSymbol
{
public ImportedSymbol(ISymbolContext context, ImportedSymbolsListItemSyntax declaringSyntax, CompileTimeImportDeclarationSyntax enclosingDeclartion, ISemanticModel sourceModel)
: base(context, declaringSyntax.Name.IdentifierName, declaringSyntax, declaringSyntax.Name)
{
EnclosingDeclaration = enclosingDeclartion;
SourceModel = sourceModel;
}
public CompileTimeImportDeclarationSyntax EnclosingDeclaration { get; }
public ImportedSymbolsListItemSyntax DeclaringImportedSymbolsListItem => (ImportedSymbolsListItemSyntax)DeclaringSyntax;
public string? OriginalSymbolName => DeclaringImportedSymbolsListItem.TryGetOriginalSymbolNameText();
public ISemanticModel SourceModel { get; }
public abstract string? Description { get; }
public ResultWithDiagnostic<ArtifactReference> TryGetArtifactReference()
=> Context.Compilation.ArtifactReferenceFactory.TryGetArtifactReference(EnclosingDeclaration, Context.SourceFile.FileUri);
}
public abstract class ImportedSymbol<T> : ImportedSymbol where T : ExportMetadata
{
public ImportedSymbol(ISymbolContext context, ImportedSymbolsListItemSyntax declaringSyntax, CompileTimeImportDeclarationSyntax enclosingDeclartion, ISemanticModel sourceModel, T exportMetadata)
: base(context, declaringSyntax, enclosingDeclartion, sourceModel)
{
ExportMetadata = exportMetadata;
}
public T ExportMetadata { get; }
public override string? Description => ExportMetadata.Description;
public override IEnumerable<ErrorDiagnostic> GetDiagnostics()
{
if (!IsSupportedImportKind())
{
yield return DiagnosticBuilder.ForPosition(DeclaringImportedSymbolsListItem.OriginalSymbolName)
.ImportedSymbolKindNotSupportedInSourceFileKind(ExportMetadata.Name, ExportMetadata.Kind, Context.SourceFile.FileKind);
}
}
private bool IsSupportedImportKind() => Context.SourceFile switch
{
BicepFile => ExportMetadata.Kind switch
{
ExportMetadataKind.Type or
ExportMetadataKind.Variable or
ExportMetadataKind.Function => true,
_ => false,
},
BicepParamFile => ExportMetadata.Kind switch
{
ExportMetadataKind.Variable or
ExportMetadataKind.Function => true,
_ => false,
},
_ => false,
};
}