Skip to content

Commit

Permalink
Merge pull request #3611 from sharwell/operation-wrapper
Browse files Browse the repository at this point in the history
Rewrite IOperationWrapper as a wrapper structure around IOperation
  • Loading branch information
sharwell committed Jul 6, 2023
2 parents 0f30141 + 9b5db19 commit b209e4e
Show file tree
Hide file tree
Showing 128 changed files with 691 additions and 292 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace StyleCop.Analyzers.Lightup
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;

internal readonly struct IAddressOfOperationWrapper : IOperationWrapper
internal readonly struct IAddressOfOperationWrapper
{
internal const string WrappedTypeName = "Microsoft.CodeAnalysis.Operations.IAddressOfOperation";
private static readonly Type WrappedType;
Expand All @@ -27,6 +27,8 @@ private IAddressOfOperationWrapper(IOperation operation)
public IOperation WrappedOperation => this.operation;
public ITypeSymbol Type => this.WrappedOperation.Type;
public IOperation Reference => ReferenceAccessor(this.WrappedOperation);
public static explicit operator IAddressOfOperationWrapper(IOperationWrapper wrapper) => FromOperation(wrapper.WrappedOperation);
public static implicit operator IOperationWrapper(IAddressOfOperationWrapper wrapper) => IOperationWrapper.FromUpcast(wrapper.WrappedOperation);
public static IAddressOfOperationWrapper FromOperation(IOperation operation)
{
if (operation == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace StyleCop.Analyzers.Lightup
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;

internal readonly struct IAnonymousFunctionOperationWrapper : IOperationWrapper
internal readonly struct IAnonymousFunctionOperationWrapper
{
internal const string WrappedTypeName = "Microsoft.CodeAnalysis.Operations.IAnonymousFunctionOperation";
private static readonly Type WrappedType;
Expand All @@ -30,6 +30,8 @@ private IAnonymousFunctionOperationWrapper(IOperation operation)
public ITypeSymbol Type => this.WrappedOperation.Type;
public IMethodSymbol Symbol => SymbolAccessor(this.WrappedOperation);
public IBlockOperationWrapper Body => IBlockOperationWrapper.FromOperation(BodyAccessor(this.WrappedOperation));
public static explicit operator IAnonymousFunctionOperationWrapper(IOperationWrapper wrapper) => FromOperation(wrapper.WrappedOperation);
public static implicit operator IOperationWrapper(IAnonymousFunctionOperationWrapper wrapper) => IOperationWrapper.FromUpcast(wrapper.WrappedOperation);
public static IAnonymousFunctionOperationWrapper FromOperation(IOperation operation)
{
if (operation == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace StyleCop.Analyzers.Lightup
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;

internal readonly struct IAnonymousObjectCreationOperationWrapper : IOperationWrapper
internal readonly struct IAnonymousObjectCreationOperationWrapper
{
internal const string WrappedTypeName = "Microsoft.CodeAnalysis.Operations.IAnonymousObjectCreationOperation";
private static readonly Type WrappedType;
Expand All @@ -27,6 +27,8 @@ private IAnonymousObjectCreationOperationWrapper(IOperation operation)
public IOperation WrappedOperation => this.operation;
public ITypeSymbol Type => this.WrappedOperation.Type;
public ImmutableArray<IOperation> Initializers => InitializersAccessor(this.WrappedOperation);
public static explicit operator IAnonymousObjectCreationOperationWrapper(IOperationWrapper wrapper) => FromOperation(wrapper.WrappedOperation);
public static implicit operator IOperationWrapper(IAnonymousObjectCreationOperationWrapper wrapper) => IOperationWrapper.FromUpcast(wrapper.WrappedOperation);
public static IAnonymousObjectCreationOperationWrapper FromOperation(IOperation operation)
{
if (operation == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace StyleCop.Analyzers.Lightup
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;

internal readonly struct IArgumentOperationWrapper : IOperationWrapper
internal readonly struct IArgumentOperationWrapper
{
internal const string WrappedTypeName = "Microsoft.CodeAnalysis.Operations.IArgumentOperation";
private static readonly Type WrappedType;
Expand All @@ -33,6 +33,8 @@ private IArgumentOperationWrapper(IOperation operation)
public IOperation Value => ValueAccessor(this.WrappedOperation);
public object InConversion => throw new NotImplementedException("Property 'IArgumentOperation.InConversion' has unsupported type 'CommonConversion'");
public object OutConversion => throw new NotImplementedException("Property 'IArgumentOperation.OutConversion' has unsupported type 'CommonConversion'");
public static explicit operator IArgumentOperationWrapper(IOperationWrapper wrapper) => FromOperation(wrapper.WrappedOperation);
public static implicit operator IOperationWrapper(IArgumentOperationWrapper wrapper) => IOperationWrapper.FromUpcast(wrapper.WrappedOperation);
public static IArgumentOperationWrapper FromOperation(IOperation operation)
{
if (operation == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace StyleCop.Analyzers.Lightup
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;

internal readonly struct IArrayCreationOperationWrapper : IOperationWrapper
internal readonly struct IArrayCreationOperationWrapper
{
internal const string WrappedTypeName = "Microsoft.CodeAnalysis.Operations.IArrayCreationOperation";
private static readonly Type WrappedType;
Expand All @@ -30,6 +30,8 @@ private IArrayCreationOperationWrapper(IOperation operation)
public ITypeSymbol Type => this.WrappedOperation.Type;
public ImmutableArray<IOperation> DimensionSizes => DimensionSizesAccessor(this.WrappedOperation);
public IArrayInitializerOperationWrapper Initializer => IArrayInitializerOperationWrapper.FromOperation(InitializerAccessor(this.WrappedOperation));
public static explicit operator IArrayCreationOperationWrapper(IOperationWrapper wrapper) => FromOperation(wrapper.WrappedOperation);
public static implicit operator IOperationWrapper(IArrayCreationOperationWrapper wrapper) => IOperationWrapper.FromUpcast(wrapper.WrappedOperation);
public static IArrayCreationOperationWrapper FromOperation(IOperation operation)
{
if (operation == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace StyleCop.Analyzers.Lightup
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;

internal readonly struct IArrayElementReferenceOperationWrapper : IOperationWrapper
internal readonly struct IArrayElementReferenceOperationWrapper
{
internal const string WrappedTypeName = "Microsoft.CodeAnalysis.Operations.IArrayElementReferenceOperation";
private static readonly Type WrappedType;
Expand All @@ -30,6 +30,8 @@ private IArrayElementReferenceOperationWrapper(IOperation operation)
public ITypeSymbol Type => this.WrappedOperation.Type;
public IOperation ArrayReference => ArrayReferenceAccessor(this.WrappedOperation);
public ImmutableArray<IOperation> Indices => IndicesAccessor(this.WrappedOperation);
public static explicit operator IArrayElementReferenceOperationWrapper(IOperationWrapper wrapper) => FromOperation(wrapper.WrappedOperation);
public static implicit operator IOperationWrapper(IArrayElementReferenceOperationWrapper wrapper) => IOperationWrapper.FromUpcast(wrapper.WrappedOperation);
public static IArrayElementReferenceOperationWrapper FromOperation(IOperation operation)
{
if (operation == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace StyleCop.Analyzers.Lightup
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;

internal readonly struct IArrayInitializerOperationWrapper : IOperationWrapper
internal readonly struct IArrayInitializerOperationWrapper
{
internal const string WrappedTypeName = "Microsoft.CodeAnalysis.Operations.IArrayInitializerOperation";
private static readonly Type WrappedType;
Expand All @@ -27,6 +27,8 @@ private IArrayInitializerOperationWrapper(IOperation operation)
public IOperation WrappedOperation => this.operation;
public ITypeSymbol Type => this.WrappedOperation.Type;
public ImmutableArray<IOperation> ElementValues => ElementValuesAccessor(this.WrappedOperation);
public static explicit operator IArrayInitializerOperationWrapper(IOperationWrapper wrapper) => FromOperation(wrapper.WrappedOperation);
public static implicit operator IOperationWrapper(IArrayInitializerOperationWrapper wrapper) => IOperationWrapper.FromUpcast(wrapper.WrappedOperation);
public static IArrayInitializerOperationWrapper FromOperation(IOperation operation)
{
if (operation == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace StyleCop.Analyzers.Lightup
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;

internal readonly struct IAssignmentOperationWrapper : IOperationWrapper
internal readonly struct IAssignmentOperationWrapper
{
internal const string WrappedTypeName = "Microsoft.CodeAnalysis.Operations.IAssignmentOperation";
private static readonly Type WrappedType;
Expand All @@ -30,6 +30,8 @@ private IAssignmentOperationWrapper(IOperation operation)
public ITypeSymbol Type => this.WrappedOperation.Type;
public IOperation Target => TargetAccessor(this.WrappedOperation);
public IOperation Value => ValueAccessor(this.WrappedOperation);
public static explicit operator IAssignmentOperationWrapper(IOperationWrapper wrapper) => FromOperation(wrapper.WrappedOperation);
public static implicit operator IOperationWrapper(IAssignmentOperationWrapper wrapper) => IOperationWrapper.FromUpcast(wrapper.WrappedOperation);
public static IAssignmentOperationWrapper FromOperation(IOperation operation)
{
if (operation == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace StyleCop.Analyzers.Lightup
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;

internal readonly struct IAwaitOperationWrapper : IOperationWrapper
internal readonly struct IAwaitOperationWrapper
{
internal const string WrappedTypeName = "Microsoft.CodeAnalysis.Operations.IAwaitOperation";
private static readonly Type WrappedType;
Expand All @@ -27,6 +27,8 @@ private IAwaitOperationWrapper(IOperation operation)
public IOperation WrappedOperation => this.operation;
public ITypeSymbol Type => this.WrappedOperation.Type;
public IOperation Operation => OperationAccessor(this.WrappedOperation);
public static explicit operator IAwaitOperationWrapper(IOperationWrapper wrapper) => FromOperation(wrapper.WrappedOperation);
public static implicit operator IOperationWrapper(IAwaitOperationWrapper wrapper) => IOperationWrapper.FromUpcast(wrapper.WrappedOperation);
public static IAwaitOperationWrapper FromOperation(IOperation operation)
{
if (operation == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace StyleCop.Analyzers.Lightup
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;

internal readonly struct IBinaryOperationWrapper : IOperationWrapper
internal readonly struct IBinaryOperationWrapper
{
internal const string WrappedTypeName = "Microsoft.CodeAnalysis.Operations.IBinaryOperation";
private static readonly Type WrappedType;
Expand Down Expand Up @@ -43,6 +43,8 @@ private IBinaryOperationWrapper(IOperation operation)
public bool IsChecked => IsCheckedAccessor(this.WrappedOperation);
public bool IsCompareText => IsCompareTextAccessor(this.WrappedOperation);
public IMethodSymbol OperatorMethod => OperatorMethodAccessor(this.WrappedOperation);
public static explicit operator IBinaryOperationWrapper(IOperationWrapper wrapper) => FromOperation(wrapper.WrappedOperation);
public static implicit operator IOperationWrapper(IBinaryOperationWrapper wrapper) => IOperationWrapper.FromUpcast(wrapper.WrappedOperation);
public static IBinaryOperationWrapper FromOperation(IOperation operation)
{
if (operation == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace StyleCop.Analyzers.Lightup
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;

internal readonly struct IBinaryPatternOperationWrapper : IOperationWrapper
internal readonly struct IBinaryPatternOperationWrapper
{
internal const string WrappedTypeName = "Microsoft.CodeAnalysis.Operations.IBinaryPatternOperation";
private static readonly Type WrappedType;
Expand All @@ -31,6 +31,8 @@ private IBinaryPatternOperationWrapper(IOperation operation)
public object OperatorKind => throw new NotImplementedException("Property 'IBinaryPatternOperation.OperatorKind' has unsupported type 'BinaryOperatorKind'");
public IPatternOperationWrapper LeftPattern => IPatternOperationWrapper.FromOperation(LeftPatternAccessor(this.WrappedOperation));
public IPatternOperationWrapper RightPattern => IPatternOperationWrapper.FromOperation(RightPatternAccessor(this.WrappedOperation));
public static explicit operator IBinaryPatternOperationWrapper(IOperationWrapper wrapper) => FromOperation(wrapper.WrappedOperation);
public static implicit operator IOperationWrapper(IBinaryPatternOperationWrapper wrapper) => IOperationWrapper.FromUpcast(wrapper.WrappedOperation);
public ITypeSymbol InputType => ((IPatternOperationWrapper)this).InputType;
public ITypeSymbol NarrowedType => ((IPatternOperationWrapper)this).NarrowedType;
public static explicit operator IBinaryPatternOperationWrapper(IPatternOperationWrapper wrapper) => FromOperation(wrapper.WrappedOperation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace StyleCop.Analyzers.Lightup
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;

internal readonly struct IBlockOperationWrapper : IOperationWrapper
internal readonly struct IBlockOperationWrapper
{
internal const string WrappedTypeName = "Microsoft.CodeAnalysis.Operations.IBlockOperation";
private static readonly Type WrappedType;
Expand All @@ -30,6 +30,8 @@ private IBlockOperationWrapper(IOperation operation)
public ITypeSymbol Type => this.WrappedOperation.Type;
public ImmutableArray<IOperation> Operations => OperationsAccessor(this.WrappedOperation);
public ImmutableArray<ILocalSymbol> Locals => LocalsAccessor(this.WrappedOperation);
public static explicit operator IBlockOperationWrapper(IOperationWrapper wrapper) => FromOperation(wrapper.WrappedOperation);
public static implicit operator IOperationWrapper(IBlockOperationWrapper wrapper) => IOperationWrapper.FromUpcast(wrapper.WrappedOperation);
public static IBlockOperationWrapper FromOperation(IOperation operation)
{
if (operation == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace StyleCop.Analyzers.Lightup
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;

internal readonly struct IBranchOperationWrapper : IOperationWrapper
internal readonly struct IBranchOperationWrapper
{
internal const string WrappedTypeName = "Microsoft.CodeAnalysis.Operations.IBranchOperation";
private static readonly Type WrappedType;
Expand All @@ -28,6 +28,8 @@ private IBranchOperationWrapper(IOperation operation)
public ITypeSymbol Type => this.WrappedOperation.Type;
public ILabelSymbol Target => TargetAccessor(this.WrappedOperation);
public object BranchKind => throw new NotImplementedException("Property 'IBranchOperation.BranchKind' has unsupported type 'BranchKind'");
public static explicit operator IBranchOperationWrapper(IOperationWrapper wrapper) => FromOperation(wrapper.WrappedOperation);
public static implicit operator IOperationWrapper(IBranchOperationWrapper wrapper) => IOperationWrapper.FromUpcast(wrapper.WrappedOperation);
public static IBranchOperationWrapper FromOperation(IOperation operation)
{
if (operation == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace StyleCop.Analyzers.Lightup
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;

internal readonly struct ICaseClauseOperationWrapper : IOperationWrapper
internal readonly struct ICaseClauseOperationWrapper
{
internal const string WrappedTypeName = "Microsoft.CodeAnalysis.Operations.ICaseClauseOperation";
private static readonly Type WrappedType;
Expand All @@ -28,6 +28,8 @@ private ICaseClauseOperationWrapper(IOperation operation)
public ITypeSymbol Type => this.WrappedOperation.Type;
public object CaseKind => throw new NotImplementedException("Property 'ICaseClauseOperation.CaseKind' has unsupported type 'CaseKind'");
public ILabelSymbol Label => LabelAccessor(this.WrappedOperation);
public static explicit operator ICaseClauseOperationWrapper(IOperationWrapper wrapper) => FromOperation(wrapper.WrappedOperation);
public static implicit operator IOperationWrapper(ICaseClauseOperationWrapper wrapper) => IOperationWrapper.FromUpcast(wrapper.WrappedOperation);
public static ICaseClauseOperationWrapper FromOperation(IOperation operation)
{
if (operation == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace StyleCop.Analyzers.Lightup
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;

internal readonly struct ICatchClauseOperationWrapper : IOperationWrapper
internal readonly struct ICatchClauseOperationWrapper
{
internal const string WrappedTypeName = "Microsoft.CodeAnalysis.Operations.ICatchClauseOperation";
private static readonly Type WrappedType;
Expand Down Expand Up @@ -39,6 +39,8 @@ private ICatchClauseOperationWrapper(IOperation operation)
public ImmutableArray<ILocalSymbol> Locals => LocalsAccessor(this.WrappedOperation);
public IOperation Filter => FilterAccessor(this.WrappedOperation);
public IBlockOperationWrapper Handler => IBlockOperationWrapper.FromOperation(HandlerAccessor(this.WrappedOperation));
public static explicit operator ICatchClauseOperationWrapper(IOperationWrapper wrapper) => FromOperation(wrapper.WrappedOperation);
public static implicit operator IOperationWrapper(ICatchClauseOperationWrapper wrapper) => IOperationWrapper.FromUpcast(wrapper.WrappedOperation);
public static ICatchClauseOperationWrapper FromOperation(IOperation operation)
{
if (operation == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace StyleCop.Analyzers.Lightup
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;

internal readonly struct ICaughtExceptionOperationWrapper : IOperationWrapper
internal readonly struct ICaughtExceptionOperationWrapper
{
internal const string WrappedTypeName = "Microsoft.CodeAnalysis.FlowAnalysis.ICaughtExceptionOperation";
private static readonly Type WrappedType;
Expand All @@ -24,6 +24,8 @@ private ICaughtExceptionOperationWrapper(IOperation operation)

public IOperation WrappedOperation => this.operation;
public ITypeSymbol Type => this.WrappedOperation.Type;
public static explicit operator ICaughtExceptionOperationWrapper(IOperationWrapper wrapper) => FromOperation(wrapper.WrappedOperation);
public static implicit operator IOperationWrapper(ICaughtExceptionOperationWrapper wrapper) => IOperationWrapper.FromUpcast(wrapper.WrappedOperation);
public static ICaughtExceptionOperationWrapper FromOperation(IOperation operation)
{
if (operation == null)
Expand Down

0 comments on commit b209e4e

Please sign in to comment.