From 216663c07bfcd958f4a8df32d0ab3422bbf42a84 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Sat, 1 Jul 2023 22:52:37 +0300 Subject: [PATCH] Cleanup Lightup after MS.CA update --- ...atOwnDisposableFieldsShouldBeDisposable.cs | 5 +- ...icInterfaceCastableImplementation.Fixer.cs | 10 ++-- ...TokenToInvocationsFixer.TypeNameVisitor.cs | 8 ++- .../CollectionPropertiesShouldBeReadOnly.cs | 3 +- .../DoNotDirectlyAwaitATask.cs | 7 ++- ...abledRuntimeMarshallingAssemblyAnalyzer.cs | 4 +- .../UseConcreteTypeAnalyzer.Collector.cs | 3 +- .../Performance/UseConcreteTypeAnalyzer.cs | 5 +- ...harpAvoidOptSuffixForNullableEnableCode.cs | 3 +- .../PreferNullLiteralCodeFixProvider.cs | 1 - ...TypeShouldHaveDefaultableFieldsAnalyzer.cs | 4 +- .../Analyzer.CSharp.Utilities.projitems | 1 - .../Compiler.CSharp/Lightup/SyntaxKindEx.cs | 13 ----- .../Compiler/Analyzer.Utilities.projitems | 4 -- .../Lightup/IMethodSymbolExtensions.cs | 30 ----------- .../Compiler/Lightup/ITypeSymbolExtensions.cs | 11 ---- .../IUsingDeclarationOperationWrapper.cs | 53 ------------------- .../Lightup/IUsingOperationExtensions.cs | 20 ------- .../Compiler/Lightup/OperationKindEx.cs | 1 - .../Lightup/OperationWrapperHelper.cs | 1 - .../Lightup/SemanticModelExtensions.cs | 16 ------ 21 files changed, 20 insertions(+), 183 deletions(-) delete mode 100644 src/Utilities/Compiler.CSharp/Lightup/SyntaxKindEx.cs delete mode 100644 src/Utilities/Compiler/Lightup/IMethodSymbolExtensions.cs delete mode 100644 src/Utilities/Compiler/Lightup/IUsingDeclarationOperationWrapper.cs delete mode 100644 src/Utilities/Compiler/Lightup/IUsingOperationExtensions.cs delete mode 100644 src/Utilities/Compiler/Lightup/SemanticModelExtensions.cs diff --git a/src/NetAnalyzers/CSharp/Microsoft.CodeQuality.Analyzers/ApiDesignGuidelines/CSharpTypesThatOwnDisposableFieldsShouldBeDisposable.cs b/src/NetAnalyzers/CSharp/Microsoft.CodeQuality.Analyzers/ApiDesignGuidelines/CSharpTypesThatOwnDisposableFieldsShouldBeDisposable.cs index 2e6d0972b4..139ddac73b 100644 --- a/src/NetAnalyzers/CSharp/Microsoft.CodeQuality.Analyzers/ApiDesignGuidelines/CSharpTypesThatOwnDisposableFieldsShouldBeDisposable.cs +++ b/src/NetAnalyzers/CSharp/Microsoft.CodeQuality.Analyzers/ApiDesignGuidelines/CSharpTypesThatOwnDisposableFieldsShouldBeDisposable.cs @@ -7,7 +7,6 @@ using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; -using Analyzer.CSharp.Utilities.Lightup; namespace Microsoft.CodeQuality.CSharp.Analyzers.ApiDesignGuidelines { @@ -30,7 +29,7 @@ protected override IEnumerable GetDisposableFieldCreations(SyntaxN { if (node is AssignmentExpressionSyntax assignment) { - if (assignment.Right.Kind() is SyntaxKind.ObjectCreationExpression or SyntaxKindEx.ImplicitObjectCreationExpression && + if (assignment.Right.Kind() is SyntaxKind.ObjectCreationExpression or SyntaxKind.ImplicitObjectCreationExpression && model.GetSymbolInfo(assignment.Left, cancellationToken).Symbol is IFieldSymbol field && disposableFields.Contains(field)) { @@ -41,7 +40,7 @@ protected override IEnumerable GetDisposableFieldCreations(SyntaxN { foreach (VariableDeclaratorSyntax fieldInit in fieldDeclarationSyntax.Declaration.Variables) { - if (fieldInit.Initializer?.Value.Kind() is SyntaxKind.ObjectCreationExpression or SyntaxKindEx.ImplicitObjectCreationExpression && + if (fieldInit.Initializer?.Value.Kind() is SyntaxKind.ObjectCreationExpression or SyntaxKind.ImplicitObjectCreationExpression && model.GetDeclaredSymbol(fieldInit, cancellationToken) is IFieldSymbol field && disposableFields.Contains(field)) { diff --git a/src/NetAnalyzers/CSharp/Microsoft.NetCore.Analyzers/InteropServices/CSharpDynamicInterfaceCastableImplementation.Fixer.cs b/src/NetAnalyzers/CSharp/Microsoft.NetCore.Analyzers/InteropServices/CSharpDynamicInterfaceCastableImplementation.Fixer.cs index c4e0633614..2e9ae7bc6e 100644 --- a/src/NetAnalyzers/CSharp/Microsoft.NetCore.Analyzers/InteropServices/CSharpDynamicInterfaceCastableImplementation.Fixer.cs +++ b/src/NetAnalyzers/CSharp/Microsoft.NetCore.Analyzers/InteropServices/CSharpDynamicInterfaceCastableImplementation.Fixer.cs @@ -5,9 +5,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Analyzer.CSharp.Utilities.Lightup; using Analyzer.Utilities; -using Analyzer.Utilities.Lightup; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp; @@ -109,7 +107,7 @@ private static SyntaxNode AddSetAccessor( SyntaxNode[] defaultMethodBodyStatements, bool includeAccessibility) { - if (!property.SetMethod!.IsInitOnly()) + if (!property.SetMethod!.IsInitOnly) { return generator.WithSetAccessorStatements(declaration, defaultMethodBodyStatements); } @@ -126,7 +124,7 @@ private static SyntaxNode AddSetAccessor( foreach (var accessor in propertyDeclaration.AccessorList!.Accessors) { - if (accessor.IsKind(SyntaxKindEx.InitAccessorDeclaration)) + if (accessor.IsKind(SyntaxKind.InitAccessorDeclaration)) { oldInitAccessor = accessor; break; @@ -140,10 +138,10 @@ private static SyntaxNode AddSetAccessor( return propertyDeclaration.WithAccessorList(propertyDeclaration.AccessorList!.AddAccessors( SyntaxFactory.AccessorDeclaration( - SyntaxKindEx.InitAccessorDeclaration, + SyntaxKind.InitAccessorDeclaration, setAccessor.AttributeLists, setAccessor.Modifiers, - SyntaxFactory.Token(SyntaxKindEx.InitKeyword), + SyntaxFactory.Token(SyntaxKind.InitKeyword), setAccessor.Body, setAccessor.ExpressionBody, setAccessor.SemicolonToken))); diff --git a/src/NetAnalyzers/CSharp/Microsoft.NetCore.Analyzers/Runtime/CSharpForwardCancellationTokenToInvocationsFixer.TypeNameVisitor.cs b/src/NetAnalyzers/CSharp/Microsoft.NetCore.Analyzers/Runtime/CSharpForwardCancellationTokenToInvocationsFixer.TypeNameVisitor.cs index ecef01bfca..cd2194d0d8 100644 --- a/src/NetAnalyzers/CSharp/Microsoft.NetCore.Analyzers/Runtime/CSharpForwardCancellationTokenToInvocationsFixer.TypeNameVisitor.cs +++ b/src/NetAnalyzers/CSharp/Microsoft.NetCore.Analyzers/Runtime/CSharpForwardCancellationTokenToInvocationsFixer.TypeNameVisitor.cs @@ -3,13 +3,11 @@ using System; using System.Diagnostics.CodeAnalysis; using System.Linq; -using Analyzer.Utilities.Lightup; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Simplification; using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; -using NullableAnnotation = Analyzer.Utilities.Lightup.NullableAnnotation; namespace Microsoft.NetCore.CSharp.Analyzers.Runtime { @@ -78,7 +76,7 @@ public override TypeSyntax VisitNamedType(INamedTypeSymbol symbol) } } - if (symbol.NullableAnnotation() == NullableAnnotation.Annotated && + if (symbol.NullableAnnotation == NullableAnnotation.Annotated && !symbol.IsValueType) { typeSyntax = AddInformationTo(NullableType(typeSyntax)); @@ -111,7 +109,7 @@ public override TypeSyntax VisitNamespace(INamespaceSymbol symbol) public override TypeSyntax VisitTypeParameter(ITypeParameterSymbol symbol) { TypeSyntax typeSyntax = AddInformationTo(ToIdentifierName(symbol.Name)); - if (symbol.NullableAnnotation() == NullableAnnotation.Annotated) + if (symbol.NullableAnnotation == NullableAnnotation.Annotated) typeSyntax = AddInformationTo(NullableType(typeSyntax)); return typeSyntax; @@ -181,7 +179,7 @@ private static IdentifierNameSyntax CreateGlobalIdentifier() private static bool TryCreateNativeIntegerType(INamedTypeSymbol symbol, [NotNullWhen(true)] out TypeSyntax? syntax) { - if (symbol.IsNativeIntegerType()) + if (symbol.IsNativeIntegerType) { syntax = IdentifierName(symbol.SpecialType == SpecialType.System_IntPtr ? "nint" : "nuint"); return true; diff --git a/src/NetAnalyzers/Core/Microsoft.CodeQuality.Analyzers/ApiDesignGuidelines/CollectionPropertiesShouldBeReadOnly.cs b/src/NetAnalyzers/Core/Microsoft.CodeQuality.Analyzers/ApiDesignGuidelines/CollectionPropertiesShouldBeReadOnly.cs index 63f6079f0f..5ef9537411 100644 --- a/src/NetAnalyzers/Core/Microsoft.CodeQuality.Analyzers/ApiDesignGuidelines/CollectionPropertiesShouldBeReadOnly.cs +++ b/src/NetAnalyzers/Core/Microsoft.CodeQuality.Analyzers/ApiDesignGuidelines/CollectionPropertiesShouldBeReadOnly.cs @@ -5,7 +5,6 @@ using System.Linq; using Analyzer.Utilities; using Analyzer.Utilities.Extensions; -using Analyzer.Utilities.Lightup; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; @@ -92,7 +91,7 @@ private static void AnalyzeSymbol(SymbolAnalysisContext context, KnownTypes know } // make sure this property is NOT an init - if (setter.IsInitOnly()) + if (setter.IsInitOnly) { return; } diff --git a/src/NetAnalyzers/Core/Microsoft.CodeQuality.Analyzers/ApiDesignGuidelines/DoNotDirectlyAwaitATask.cs b/src/NetAnalyzers/Core/Microsoft.CodeQuality.Analyzers/ApiDesignGuidelines/DoNotDirectlyAwaitATask.cs index 47cd1b5b3f..8f03ec49a3 100644 --- a/src/NetAnalyzers/Core/Microsoft.CodeQuality.Analyzers/ApiDesignGuidelines/DoNotDirectlyAwaitATask.cs +++ b/src/NetAnalyzers/Core/Microsoft.CodeQuality.Analyzers/ApiDesignGuidelines/DoNotDirectlyAwaitATask.cs @@ -4,7 +4,6 @@ using System.Linq; using Analyzer.Utilities; using Analyzer.Utilities.Extensions; -using Analyzer.Utilities.Lightup; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Operations; @@ -75,7 +74,7 @@ public override void Initialize(AnalysisContext context) if (configuredAsyncDisposable is not null) { context.RegisterOperationAction(context => AnalyzeUsingOperation(context, configuredAsyncDisposable), OperationKind.Using); - context.RegisterOperationAction(context => AnalyzeUsingDeclarationOperation(context, configuredAsyncDisposable), OperationKindEx.UsingDeclaration); + context.RegisterOperationAction(context => AnalyzeUsingDeclarationOperation(context, configuredAsyncDisposable), OperationKind.UsingDeclaration); } } }); @@ -97,7 +96,7 @@ private static void AnalyzeAwaitOperation(OperationAnalysisContext context, Immu private static void AnalyzeUsingOperation(OperationAnalysisContext context, INamedTypeSymbol configuredAsyncDisposable) { var usingExpression = (IUsingOperation)context.Operation; - if (!usingExpression.IsAsynchronous()) + if (!usingExpression.IsAsynchronous) { return; } @@ -121,7 +120,7 @@ private static void AnalyzeUsingOperation(OperationAnalysisContext context, INam private static void AnalyzeUsingDeclarationOperation(OperationAnalysisContext context, INamedTypeSymbol configuredAsyncDisposable) { - var usingExpression = IUsingDeclarationOperationWrapper.FromOperation(context.Operation); + var usingExpression = (IUsingDeclarationOperation)context.Operation; if (!usingExpression.IsAsynchronous) { return; diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/InteropServices/DisableRuntimeMarshallingAnalyzer.DisabledRuntimeMarshallingAssemblyAnalyzer.cs b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/InteropServices/DisableRuntimeMarshallingAnalyzer.DisabledRuntimeMarshallingAssemblyAnalyzer.cs index 17d05c4c6e..36e13e7e6e 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/InteropServices/DisableRuntimeMarshallingAnalyzer.DisabledRuntimeMarshallingAssemblyAnalyzer.cs +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/InteropServices/DisableRuntimeMarshallingAnalyzer.DisabledRuntimeMarshallingAssemblyAnalyzer.cs @@ -100,7 +100,7 @@ public void AnalyzeFunctionPointerCall(OperationAnalysisContext context) { var functionPointerInvocation = IFunctionPointerInvocationOperationWrapper.FromOperation(context.Operation); - if (functionPointerInvocation.GetFunctionPointerSignature().CallingConvention() == System.Reflection.Metadata.SignatureCallingConvention.Default) + if (functionPointerInvocation.GetFunctionPointerSignature().CallingConvention == System.Reflection.Metadata.SignatureCallingConvention.Default) { return; } @@ -147,7 +147,7 @@ private void AnalyzeMethod(Action reportDiagnostic, IMethodSymbol me reportDiagnostic(method.CreateDiagnostic(FeatureUnsupportedWhenRuntimeMarshallingDisabledSetLastErrorTrue)); } - if (!method.MethodImplementationFlags().HasFlag(System.Reflection.MethodImplAttributes.PreserveSig)) + if (!method.MethodImplementationFlags.HasFlag(System.Reflection.MethodImplAttributes.PreserveSig)) { reportDiagnostic(method.CreateDiagnostic(FeatureUnsupportedWhenRuntimeMarshallingDisabledHResultSwapping)); } diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Performance/UseConcreteTypeAnalyzer.Collector.cs b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Performance/UseConcreteTypeAnalyzer.Collector.cs index 129fb9a316..5b474ccd94 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Performance/UseConcreteTypeAnalyzer.Collector.cs +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Performance/UseConcreteTypeAnalyzer.Collector.cs @@ -6,7 +6,6 @@ using System.Linq; using System.Threading; using Analyzer.Utilities.Extensions; -using Analyzer.Utilities.Lightup; using Analyzer.Utilities.PooledObjects; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Operations; @@ -416,7 +415,7 @@ private void GetValueTypes(List values, IOperation? op) if (values.Count > oldCount) { // erase any potential nullable annotations of the left-hand value since when the value is null, it doesn't get used - values[^1] = values[^1].WithNullableAnnotation(Analyzer.Utilities.Lightup.NullableAnnotation.NotAnnotated); + values[^1] = values[^1].WithNullableAnnotation(CodeAnalysis.NullableAnnotation.NotAnnotated); } GetValueTypes(values, colOp.WhenNull); diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Performance/UseConcreteTypeAnalyzer.cs b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Performance/UseConcreteTypeAnalyzer.cs index f99fc82d35..fbb1a53eb1 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Performance/UseConcreteTypeAnalyzer.cs +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Performance/UseConcreteTypeAnalyzer.cs @@ -5,7 +5,6 @@ using System.Linq; using Analyzer.Utilities; using Analyzer.Utilities.Extensions; -using Analyzer.Utilities.Lightup; using Analyzer.Utilities.PooledObjects; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; @@ -257,9 +256,9 @@ void Evaluate(ISymbol affectedSymbol, ITypeSymbol fromType, PooledConcurrentSet< } var toType = types.Single(); - if (assignedNull || fromType.NullableAnnotation() == Analyzer.Utilities.Lightup.NullableAnnotation.Annotated) + if (assignedNull || fromType.NullableAnnotation == NullableAnnotation.Annotated) { - toType = toType.WithNullableAnnotation(Analyzer.Utilities.Lightup.NullableAnnotation.Annotated); + toType = toType.WithNullableAnnotation(NullableAnnotation.Annotated); } if (!toType.DerivesFrom(fromType.OriginalDefinition)) diff --git a/src/Roslyn.Diagnostics.Analyzers/CSharp/CSharpAvoidOptSuffixForNullableEnableCode.cs b/src/Roslyn.Diagnostics.Analyzers/CSharp/CSharpAvoidOptSuffixForNullableEnableCode.cs index 78b1480466..bd990a3db2 100644 --- a/src/Roslyn.Diagnostics.Analyzers/CSharp/CSharpAvoidOptSuffixForNullableEnableCode.cs +++ b/src/Roslyn.Diagnostics.Analyzers/CSharp/CSharpAvoidOptSuffixForNullableEnableCode.cs @@ -7,7 +7,6 @@ using System.Threading; using Analyzer.Utilities; using Analyzer.Utilities.Extensions; -using Analyzer.Utilities.Lightup; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -81,7 +80,7 @@ private static void ReportOnInvalidIdentifier(SyntaxToken identifier, SemanticMo private static bool ShouldReport(ISymbol symbol) { - if (symbol?.GetMemberOrLocalOrParameterType()?.NullableAnnotation() != Analyzer.Utilities.Lightup.NullableAnnotation.Annotated) + if (symbol?.GetMemberOrLocalOrParameterType()?.NullableAnnotation != NullableAnnotation.Annotated) { // Not in a nullable context, bail-out return false; diff --git a/src/Roslyn.Diagnostics.Analyzers/CSharp/PreferNullLiteralCodeFixProvider.cs b/src/Roslyn.Diagnostics.Analyzers/CSharp/PreferNullLiteralCodeFixProvider.cs index bdf34c5a3e..640cf3d17e 100644 --- a/src/Roslyn.Diagnostics.Analyzers/CSharp/PreferNullLiteralCodeFixProvider.cs +++ b/src/Roslyn.Diagnostics.Analyzers/CSharp/PreferNullLiteralCodeFixProvider.cs @@ -6,7 +6,6 @@ using System.Composition; using System.Threading; using System.Threading.Tasks; -using Analyzer.Utilities.Lightup; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; diff --git a/src/Roslyn.Diagnostics.Analyzers/Core/DefaultableTypeShouldHaveDefaultableFieldsAnalyzer.cs b/src/Roslyn.Diagnostics.Analyzers/Core/DefaultableTypeShouldHaveDefaultableFieldsAnalyzer.cs index 8e698233e8..8280ca78d9 100644 --- a/src/Roslyn.Diagnostics.Analyzers/Core/DefaultableTypeShouldHaveDefaultableFieldsAnalyzer.cs +++ b/src/Roslyn.Diagnostics.Analyzers/Core/DefaultableTypeShouldHaveDefaultableFieldsAnalyzer.cs @@ -6,10 +6,8 @@ using System.Collections.Immutable; using Analyzer.Utilities; using Analyzer.Utilities.Extensions; -using Analyzer.Utilities.Lightup; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; -using NullableAnnotation = Analyzer.Utilities.Lightup.NullableAnnotation; namespace Roslyn.Diagnostics.Analyzers { @@ -114,7 +112,7 @@ private static bool IsDefaultable(ITypeSymbol type, INamedTypeSymbol nonDefaulta case TypeKind.Class: case TypeKind.Interface: case TypeKind.Delegate: - return type.NullableAnnotation() != NullableAnnotation.NotAnnotated; + return type.NullableAnnotation != NullableAnnotation.NotAnnotated; case TypeKind.Enum: return true; diff --git a/src/Utilities/Compiler.CSharp/Analyzer.CSharp.Utilities.projitems b/src/Utilities/Compiler.CSharp/Analyzer.CSharp.Utilities.projitems index d436a449e6..efd3b3e0e5 100644 --- a/src/Utilities/Compiler.CSharp/Analyzer.CSharp.Utilities.projitems +++ b/src/Utilities/Compiler.CSharp/Analyzer.CSharp.Utilities.projitems @@ -9,7 +9,6 @@ Analyzer.CSharp.Utilities - \ No newline at end of file diff --git a/src/Utilities/Compiler.CSharp/Lightup/SyntaxKindEx.cs b/src/Utilities/Compiler.CSharp/Lightup/SyntaxKindEx.cs deleted file mode 100644 index b2f9805d33..0000000000 --- a/src/Utilities/Compiler.CSharp/Lightup/SyntaxKindEx.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information. - -using Microsoft.CodeAnalysis.CSharp; - -namespace Analyzer.CSharp.Utilities.Lightup -{ - internal static class SyntaxKindEx - { - public const SyntaxKind InitKeyword = (SyntaxKind)8443; - public const SyntaxKind InitAccessorDeclaration = (SyntaxKind)9060; - public const SyntaxKind ImplicitObjectCreationExpression = (SyntaxKind)8659; - } -} diff --git a/src/Utilities/Compiler/Analyzer.Utilities.projitems b/src/Utilities/Compiler/Analyzer.Utilities.projitems index 175e3705d4..4ece31a81d 100644 --- a/src/Utilities/Compiler/Analyzer.Utilities.projitems +++ b/src/Utilities/Compiler/Analyzer.Utilities.projitems @@ -65,20 +65,16 @@ - - - - diff --git a/src/Utilities/Compiler/Lightup/IMethodSymbolExtensions.cs b/src/Utilities/Compiler/Lightup/IMethodSymbolExtensions.cs deleted file mode 100644 index ba952b18d3..0000000000 --- a/src/Utilities/Compiler/Lightup/IMethodSymbolExtensions.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information. - -using System; -using System.Reflection; -using System.Reflection.Metadata; -using Microsoft.CodeAnalysis; - -namespace Analyzer.Utilities.Lightup -{ - internal static class IMethodSymbolExtensions - { - private static readonly Func s_isInitOnly - = LightupHelpers.CreateSymbolPropertyAccessor(typeof(IMethodSymbol), "IsInitOnly", false); - - private static readonly Func s_methodImplementationFlags - = LightupHelpers.CreateSymbolPropertyAccessor(typeof(IMethodSymbol), "MethodImplementationFlags", MethodImplAttributes.Managed); - - private static readonly Func s_callingConvention - = LightupHelpers.CreateSymbolPropertyAccessor(typeof(IMethodSymbol), "CallingConvention", SignatureCallingConvention.Default); - - public static bool IsInitOnly(this IMethodSymbol methodSymbol) - => s_isInitOnly(methodSymbol); - - public static MethodImplAttributes MethodImplementationFlags(this IMethodSymbol methodSymbol) - => s_methodImplementationFlags(methodSymbol); - - public static SignatureCallingConvention CallingConvention(this IMethodSymbol methodSymbol) - => s_callingConvention(methodSymbol); - } -} diff --git a/src/Utilities/Compiler/Lightup/ITypeSymbolExtensions.cs b/src/Utilities/Compiler/Lightup/ITypeSymbolExtensions.cs index a8bd229613..d86f3795d1 100644 --- a/src/Utilities/Compiler/Lightup/ITypeSymbolExtensions.cs +++ b/src/Utilities/Compiler/Lightup/ITypeSymbolExtensions.cs @@ -10,19 +10,8 @@ internal static class ITypeSymbolExtensions private static readonly Func s_nullableAnnotation = LightupHelpers.CreateSymbolPropertyAccessor(typeof(ITypeSymbol), nameof(NullableAnnotation), fallbackResult: Lightup.NullableAnnotation.None); - private static readonly Func s_withNullableAnnotation - = LightupHelpers.CreateSymbolWithPropertyAccessor(typeof(ITypeSymbol), nameof(NullableAnnotation), fallbackResult: Lightup.NullableAnnotation.None); - - private static readonly Func s_isNativeIntegerType - = LightupHelpers.CreateSymbolPropertyAccessor(typeof(ITypeSymbol), nameof(IsNativeIntegerType), fallbackResult: false); - public static NullableAnnotation NullableAnnotation(this ITypeSymbol typeSymbol) => s_nullableAnnotation(typeSymbol); - public static ITypeSymbol WithNullableAnnotation(this ITypeSymbol typeSymbol, NullableAnnotation nullableAnnotation) - => s_withNullableAnnotation(typeSymbol, nullableAnnotation); - - public static bool IsNativeIntegerType(this ITypeSymbol typeSymbol) - => s_isNativeIntegerType(typeSymbol); } } diff --git a/src/Utilities/Compiler/Lightup/IUsingDeclarationOperationWrapper.cs b/src/Utilities/Compiler/Lightup/IUsingDeclarationOperationWrapper.cs deleted file mode 100644 index 114a214b68..0000000000 --- a/src/Utilities/Compiler/Lightup/IUsingDeclarationOperationWrapper.cs +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information. - -#if HAS_IOPERATION - -namespace Analyzer.Utilities.Lightup -{ - using System; - using System.Diagnostics.CodeAnalysis; - using Microsoft.CodeAnalysis; - using Microsoft.CodeAnalysis.Operations; - - [SuppressMessage("Performance", "CA1815:Override equals and operator equals on value types", Justification = "Not a comparable instance.")] - internal readonly struct IUsingDeclarationOperationWrapper : IOperationWrapper - { - internal const string WrappedTypeName = "Microsoft.CodeAnalysis.Operations.IUsingDeclarationOperation"; - private static readonly Type? WrappedType = OperationWrapperHelper.GetWrappedType(typeof(IUsingDeclarationOperationWrapper)); - - private static readonly Func DeclarationGroupAccessor = LightupHelpers.CreateOperationPropertyAccessor(WrappedType, nameof(DeclarationGroup), fallbackResult: null!); - private static readonly Func IsAsynchronousAccessor = LightupHelpers.CreateOperationPropertyAccessor(WrappedType, nameof(IsAsynchronous), fallbackResult: false); - - private IUsingDeclarationOperationWrapper(IOperation operation) - { - WrappedOperation = operation; - } - - public IOperation WrappedOperation { get; } - public ITypeSymbol? Type => this.WrappedOperation.Type; - public IVariableDeclarationGroupOperation DeclarationGroup => DeclarationGroupAccessor(WrappedOperation); - public bool IsAsynchronous => IsAsynchronousAccessor(this.WrappedOperation); - - public static IUsingDeclarationOperationWrapper FromOperation(IOperation operation) - { - if (operation == null) - { - return default; - } - - if (!IsInstance(operation)) - { - throw new InvalidCastException($"Cannot cast '{operation.GetType().FullName}' to '{WrappedTypeName}'"); - } - - return new IUsingDeclarationOperationWrapper(operation); - } - - public static bool IsInstance(IOperation operation) - { - return operation != null && LightupHelpers.CanWrapOperation(operation, WrappedType); - } - } -} - -#endif diff --git a/src/Utilities/Compiler/Lightup/IUsingOperationExtensions.cs b/src/Utilities/Compiler/Lightup/IUsingOperationExtensions.cs deleted file mode 100644 index 916056e21a..0000000000 --- a/src/Utilities/Compiler/Lightup/IUsingOperationExtensions.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information. - -#if HAS_IOPERATION - -using System; -using Microsoft.CodeAnalysis.Operations; - -namespace Analyzer.Utilities.Lightup -{ - internal static class IUsingOperationExtensions - { - private static readonly Func s_isAsynchronous - = LightupHelpers.CreateOperationPropertyAccessor(typeof(IUsingOperation), nameof(IsAsynchronous), fallbackResult: false); - - public static bool IsAsynchronous(this IUsingOperation usingOperation) - => s_isAsynchronous(usingOperation); - } -} - -#endif diff --git a/src/Utilities/Compiler/Lightup/OperationKindEx.cs b/src/Utilities/Compiler/Lightup/OperationKindEx.cs index 83187189d8..b4a8661bc5 100644 --- a/src/Utilities/Compiler/Lightup/OperationKindEx.cs +++ b/src/Utilities/Compiler/Lightup/OperationKindEx.cs @@ -8,7 +8,6 @@ namespace Analyzer.Utilities.Lightup { internal static class OperationKindEx { - public const OperationKind UsingDeclaration = (OperationKind)0x6c; public const OperationKind FunctionPointerInvocation = (OperationKind)0x78; public const OperationKind ImplicitIndexerReference = (OperationKind)0x7b; public const OperationKind Attribute = (OperationKind)0x7d; diff --git a/src/Utilities/Compiler/Lightup/OperationWrapperHelper.cs b/src/Utilities/Compiler/Lightup/OperationWrapperHelper.cs index bbc6af2065..b8bd9269ae 100644 --- a/src/Utilities/Compiler/Lightup/OperationWrapperHelper.cs +++ b/src/Utilities/Compiler/Lightup/OperationWrapperHelper.cs @@ -14,7 +14,6 @@ internal static class OperationWrapperHelper private static readonly Assembly s_codeAnalysisAssembly = typeof(SyntaxNode).GetTypeInfo().Assembly; private static readonly ImmutableDictionary WrappedTypes = ImmutableDictionary.Create() - .Add(typeof(IUsingDeclarationOperationWrapper), s_codeAnalysisAssembly.GetType(IUsingDeclarationOperationWrapper.WrappedTypeName)) .Add(typeof(IFunctionPointerInvocationOperationWrapper), s_codeAnalysisAssembly.GetType(IFunctionPointerInvocationOperationWrapper.WrappedTypeName)) .Add(typeof(INegatedPatternOperationWrapper), s_codeAnalysisAssembly.GetType(INegatedPatternOperationWrapper.WrappedTypeName)); diff --git a/src/Utilities/Compiler/Lightup/SemanticModelExtensions.cs b/src/Utilities/Compiler/Lightup/SemanticModelExtensions.cs deleted file mode 100644 index d39c713300..0000000000 --- a/src/Utilities/Compiler/Lightup/SemanticModelExtensions.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information. - -using System; -using Microsoft.CodeAnalysis; - -namespace Analyzer.Utilities.Lightup -{ - internal static class SemanticModelExtensions - { - private static readonly Func s_getNullableContext - = LightupHelpers.CreateAccessorWithArgument(typeof(SemanticModel), "semanticModel", typeof(int), "position", nameof(GetNullableContext), fallbackResult: NullableContext.Disabled); - - public static NullableContext GetNullableContext(this SemanticModel semanticModel, int position) - => s_getNullableContext(semanticModel, position); - } -}