Skip to content

Commit 911aee6

Browse files
committed
Use distinct messages for the two BestFriend analyzers
1 parent 25c3b62 commit 911aee6

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

tools-local/Microsoft.ML.InternalCodeAnalyzer/BestFriendAnalyzer.cs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@ public sealed class BestFriendAnalyzer : DiagnosticAnalyzer
1717
private const string Category = "Access";
1818
internal const string DiagnosticId = "MSML_NoBestFriendInternal";
1919

20-
private const string Title = "Cross-assembly internal access requires referenced item to have " + AttributeName + " attribute.";
21-
private const string Format = "Access of '{0}' is a cross assembly internal " +
20+
private string Title => "Cross-assembly internal access requires referenced item to have " + _attributeName + " attribute.";
21+
private string Format => "Access of '{0}' is a cross assembly internal " +
2222
"reference, and the declaring assembly wants these accesses to be on something " +
23-
"with the attribute " + AttributeName + ".";
24-
private const string Description =
23+
"with the attribute " + _attributeName + ".";
24+
private string Description =>
2525
"The identifier indicated is defined as an internal member of an assembly that has the " +
26-
AssemblyAttributeName + " assembly-level attribute set. Even with friend access to that " +
27-
"assembly, such a usage requires that the item have the " + AttributeName + " on it.";
26+
_assemblyAttributeName + " assembly-level attribute set. Even with friend access to that " +
27+
"assembly, such a usage requires that the item have the " + _attributeName + " on it.";
2828

29-
private static DiagnosticDescriptor Rule =
29+
private DiagnosticDescriptor Rule =>
3030
new DiagnosticDescriptor(DiagnosticId, Title, Format, Category,
3131
DiagnosticSeverity.Warning, isEnabledByDefault: true, description: Description);
3232

33-
private const string AttributeName = "Microsoft.ML.BestFriendAttribute (or Microsoft.ML.Runtime.Internal.CpuMath.BestFriendAttribute)";
34-
private const string AssemblyAttributeName = "Microsoft.ML.WantsToBeBestFriendsAttribute (or Microsoft.ML.Runtime.Internal.CpuMath.WantsToBeBestFriendsAttribute)";
33+
private string _attributeName;
34+
private string _assemblyAttributeName;
3535

3636
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics =>
3737
ImmutableArray.Create(Rule);
@@ -110,8 +110,15 @@ private void AnalyzeCore(SemanticModelAnalysisContext context, string attributeN
110110

111111
private void Analyze(SemanticModelAnalysisContext context)
112112
{
113-
AnalyzeCore(context, "Microsoft.ML.BestFriendAttribute", "Microsoft.ML.WantsToBeBestFriendsAttribute");
114-
AnalyzeCore(context, "Microsoft.ML.Hidden.BestFriendAttribute", "Microsoft.ML.Hidden.WantsToBeBestFriendsAttribute");
113+
// Analyzer function for BestFriend defined in Microsoft.ML
114+
_attributeName = "Microsoft.ML.BestFriendAttribute";
115+
_assemblyAttributeName = "Microsoft.ML.WantsToBeBestFriendsAttribute";
116+
AnalyzeCore(context, _attributeName, _assemblyAttributeName);
117+
118+
// Analyzer function for BestFriend defined in Microsoft.ML.Hidden
119+
_attributeName = "Microsoft.ML.Hidden.BestFriendAttribute";
120+
_assemblyAttributeName = "Microsoft.ML.Hidden.WantsToBeBestFriendsAttribute";
121+
AnalyzeCore(context, _attributeName, _assemblyAttributeName);
115122
}
116123
}
117124
}

0 commit comments

Comments
 (0)