Skip to content

Commit

Permalink
ShimLayer: Add support for OperationInterfaces (#9624)
Browse files Browse the repository at this point in the history
  • Loading branch information
costin-zaharia-sonarsource committed Aug 9, 2024
1 parent d18f669 commit 3191807
Show file tree
Hide file tree
Showing 2 changed files with 423 additions and 432 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ private void GenerateOperationInterface(in GeneratorExecutionContext context, In
continue;
}

var propertyType = property.NeedsWrapper ? SyntaxFactory.IdentifierName(property.Type + "Wrapper") : property.AccessorResultType;
var propertyType = property.NeedsWrapper ? SyntaxFactory.IdentifierName(property.WrappedType) : property.AccessorResultType; // Sonar

// ConstructorAccessor(this.WrappedOperation)
var evaluatedAccessor = SyntaxFactory.InvocationExpression(
Expand Down Expand Up @@ -321,7 +321,7 @@ private void GenerateOperationInterface(in GeneratorExecutionContext context, In

var propertyType = property.IsSkipped
? SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.ObjectKeyword))
: property.NeedsWrapper ? SyntaxFactory.IdentifierName(property.Type + "Wrapper") : property.AccessorResultType;
: property.NeedsWrapper ? SyntaxFactory.IdentifierName(property.WrappedType) : property.AccessorResultType; // Sonar

// public IOperation Instance => ((IMemberReferenceOperationWrapper)this).Instance;
members = members.Add(SyntaxFactory.PropertyDeclaration(
Expand Down Expand Up @@ -1028,12 +1028,14 @@ public PropertyData(XElement node)
this.Name = node.Attribute("Name").Value;
this.AccessorName = this.Name + "Accessor";
this.Type = node.Attribute("Type").Value;
this.TypeNonNullable = Type.TrimEnd('?'); // Sonar - When comparing types as strings, the nullable suffix should be ignored.
this.WrappedType = TypeNonNullable + "Wrapper"; // Sonar

this.IsNew = node.Attribute("New")?.Value == "true";
this.IsPublicProperty = node.Attribute("Internal")?.Value != "true";
this.IsOverride = node.Attribute("Override")?.Value == "true";

this.IsSkipped = this.Type switch
this.IsSkipped = this.TypeNonNullable switch // Sonar
{
"ArgumentKind" => true,
"BranchKind" => true,
Expand All @@ -1048,16 +1050,16 @@ public PropertyData(XElement node)
_ => !this.IsPublicProperty || this.IsOverride,
};

this.NeedsWrapper = IsAnyOperation(this.Type) && this.Type != "IOperation";
this.IsDerivedOperationArray = IsAnyOperationArray(this.Type) && this.Type != "ImmutableArray<IOperation>";
this.NeedsWrapper = IsAnyOperation(TypeNonNullable) && TypeNonNullable != "IOperation"; // Sonar
this.IsDerivedOperationArray = IsAnyOperationArray(TypeNonNullable) && TypeNonNullable != "ImmutableArray<IOperation>"; // Sonar

if (this.IsDerivedOperationArray)
{
this.AccessorResultType = SyntaxFactory.GenericName(
identifier: SyntaxFactory.Identifier("ImmutableArray"),
typeArgumentList: SyntaxFactory.TypeArgumentList(SyntaxFactory.SingletonSeparatedList<TypeSyntax>(SyntaxFactory.IdentifierName("IOperation"))));
}
else if (IsAnyOperation(this.Type))
else if (IsAnyOperation(TypeNonNullable)) // Sonar
{
this.AccessorResultType = SyntaxFactory.IdentifierName("IOperation");
}
Expand All @@ -1071,7 +1073,7 @@ public PropertyData(XElement node)

public bool IsPublicProperty { get; }

public bool IsOverride{ get; } // Added by Sonar. Usages are also by Sonar.
public bool IsOverride { get; } // Added by Sonar. Usages are also by Sonar.

public bool IsSkipped { get; }

Expand All @@ -1081,6 +1083,10 @@ public PropertyData(XElement node)

public string Type { get; }

public string TypeNonNullable { get; } // Sonar

public string WrappedType { get; } // Sonar

public bool NeedsWrapper { get; }

public bool IsDerivedOperationArray { get; }
Expand Down
Loading

0 comments on commit 3191807

Please sign in to comment.