Skip to content

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Taillefer committed Aug 3, 2023
1 parent 0d27608 commit 95a036b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
24 changes: 12 additions & 12 deletions src/Generators/Microsoft.Gen.Logging/Emission/Emitter.Method.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void GenPropertyLoads(LoggingMethod lm, string stateName, out int numReservedUnc
{
if (NeedsASlot(p))
{
if (p.ClassificationAttributeType != null)
if (p.HasDataClassification)
{
numClassifiedProps++;
}
Expand All @@ -221,7 +221,7 @@ void GenPropertyLoads(LoggingMethod lm, string stateName, out int numReservedUnc
{
p.TraverseParameterPropertiesTransitively((_, member) =>
{
if (member.ClassificationAttributeType != null)
if (member.HasDataClassification)
{
numClassifiedProps++;
}
Expand All @@ -248,7 +248,7 @@ void GenPropertyLoads(LoggingMethod lm, string stateName, out int numReservedUnc
int count = numReservedUnclassifiedProps;
foreach (var p in lm.Parameters)
{
if (NeedsASlot(p) && p.ClassificationAttributeType == null)
if (NeedsASlot(p) && !p.HasDataClassification)
{
var key = $"\"{lm.GetParameterNameInTemplate(p)}\"";

Expand Down Expand Up @@ -277,7 +277,7 @@ void GenPropertyLoads(LoggingMethod lm, string stateName, out int numReservedUnc
{
p.TraverseParameterPropertiesTransitively((propertyChain, member) =>
{
if (member.ClassificationAttributeType == null)
if (!member.HasDataClassification)
{
var propName = PropertyChainToString(propertyChain, member, "_", omitParameterName: p.OmitParameterName);
var accessExpression = PropertyChainToString(propertyChain, member, "?.", nonNullSeparator: ".");
Expand Down Expand Up @@ -309,10 +309,10 @@ void GenPropertyLoads(LoggingMethod lm, string stateName, out int numReservedUnc
int count = numReservedClassifiedProps;
foreach (var p in lm.Parameters)
{
if (NeedsASlot(p) && p.ClassificationAttributeType != null)
if (NeedsASlot(p) && p.HasDataClassification)
{
var key = $"\"{lm.GetParameterNameInTemplate(p)}\"";
var classification = $"_{EncodeTypeName(p.ClassificationAttributeType)}_Classification";
var classification = $"_{EncodeTypeName(p.ClassificationAttributeType!)}_Classification";

var value = ShouldStringify(p.Type)
? ConvertToString(p, p.NameWithAt)
Expand All @@ -328,13 +328,13 @@ void GenPropertyLoads(LoggingMethod lm, string stateName, out int numReservedUnc
{
p.TraverseParameterPropertiesTransitively((propertyChain, member) =>
{
if (member.ClassificationAttributeType != null)
if (member.HasDataClassification)
{
var propName = PropertyChainToString(propertyChain, member, "_", omitParameterName: p.OmitParameterName);
var accessExpression = PropertyChainToString(propertyChain, member, "?.", nonNullSeparator: ".");
var value = ConvertPropertyToString(member, accessExpression);
var classification = $"_{EncodeTypeName(member.ClassificationAttributeType)}_Classification";
var classification = $"_{EncodeTypeName(member.ClassificationAttributeType!)}_Classification";
OutLn($"{stateName}.ClassifiedPropertyArray[{--count}] = new(\"{propName}\", {value}, {classification});");
}
Expand All @@ -349,7 +349,7 @@ void GenPropertyLoads(LoggingMethod lm, string stateName, out int numReservedUnc
{
p.TraverseParameterPropertiesTransitively((propertyChain, member) =>
{
if (member.ClassificationAttributeType == null)
if (!member.HasDataClassification)
{
var propName = PropertyChainToString(propertyChain, member, "_", omitParameterName: p.OmitParameterName);
var accessExpression = PropertyChainToString(propertyChain, member, "?.", nonNullSeparator: ".");
Expand All @@ -372,7 +372,7 @@ void GenPropertyLoads(LoggingMethod lm, string stateName, out int numReservedUnc
var accessExpression = PropertyChainToString(propertyChain, member, "?.", nonNullSeparator: ".");
var value = ConvertPropertyToString(member, accessExpression);
var classification = $"_{EncodeTypeName(member.ClassificationAttributeType)}_Classification";
var classification = $"_{EncodeTypeName(member.ClassificationAttributeType!)}_Classification";
var skipNull = member.PotentiallyNull
? $"if ({value} != null) "
Expand Down Expand Up @@ -406,7 +406,7 @@ bool GenVariableAssignments(LoggingMethod lm, string lambdaStateName, int numRes
int index = numReservedUnclassifiedProps - 1;
foreach (var p in lm.Parameters)
{
if (NeedsASlot(p) && p.ClassificationAttributeType == null)
if (NeedsASlot(p) && !p.HasDataClassification)
{
if (p.UsedAsTemplate)
{
Expand All @@ -433,7 +433,7 @@ bool GenVariableAssignments(LoggingMethod lm, string lambdaStateName, int numRes
index = numReservedClassifiedProps - 1;
foreach (var p in lm.Parameters)
{
if (NeedsASlot(p) && p.ClassificationAttributeType != null)
if (NeedsASlot(p) && p.HasDataClassification)
{
if (p.UsedAsTemplate)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Generators/Microsoft.Gen.Logging/Emission/Emitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private void GenType(LoggingType lt)
OutOpenBrace();

var isRedactionRequired =
lt.Methods.SelectMany(static lm => lm.Parameters).Any(static lp => lp.ClassificationAttributeType != null)
lt.Methods.SelectMany(static lm => lm.Parameters).Any(static lp => lp.HasDataClassification)
|| lt.Methods.SelectMany(static lm => GetLogPropertiesAttributes(lm)).Any();

if (isRedactionRequired)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public string PotentiallyNullableType
// but instead is supposed to be taken as a normal parameter.
public bool IsNormalParameter => !IsLogger && !IsException && !IsLogLevel;

public bool HasDataClassification => ClassificationAttributeType != null;
public bool HasProperties => PropertiesToLog.Count > 0;
public bool HasPropsProvider => LogPropertiesProvider is not null;
public bool PotentiallyNull => (IsReference && !IsLogger) || IsNullable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ internal sealed record LoggingProperty(
bool ImplementsIFormattable,
IReadOnlyCollection<LoggingProperty> TransitiveMembers)
{
public bool HasDataClassification => ClassificationAttributeType != null;
public string NameWithAt => NeedsAtSign ? "@" + Name : Name;
public bool PotentiallyNull => IsReference || IsNullable;
}

0 comments on commit 95a036b

Please sign in to comment.