Skip to content

Commit

Permalink
Merge pull request #6726 from Youssef1313/lightup-cleanup
Browse files Browse the repository at this point in the history
Cleanup Lightup after MS.CA update
  • Loading branch information
mavasani committed Jul 3, 2023
2 parents 9653f96 + 216663c commit 3651e8f
Show file tree
Hide file tree
Showing 21 changed files with 20 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -30,7 +29,7 @@ protected override IEnumerable<IFieldSymbol> 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))
{
Expand All @@ -41,7 +40,7 @@ protected override IEnumerable<IFieldSymbol> 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))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
Expand All @@ -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)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
});
Expand All @@ -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;
}
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -147,7 +147,7 @@ private void AnalyzeMethod(Action<Diagnostic> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -416,7 +415,7 @@ private void GetValueTypes(List<ITypeSymbol> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<Import_RootNamespace>Analyzer.CSharp.Utilities</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Lightup\SyntaxKindEx.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\SyntaxNodeExtensions.cs" />
</ItemGroup>
</Project>
13 changes: 0 additions & 13 deletions src/Utilities/Compiler.CSharp/Lightup/SyntaxKindEx.cs

This file was deleted.

4 changes: 0 additions & 4 deletions src/Utilities/Compiler/Analyzer.Utilities.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,16 @@
<Compile Include="$(MSBuildThisFileDirectory)Extensions\WellKnownDiagnosticTagsExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Index.cs" />
<Compile Include="$(MSBuildThisFileDirectory)IsExternalInit.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Lightup\IMethodSymbolExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Lightup\INegatedPatternOperationWrapper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Lightup\IOperationWrapper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Lightup\ITypeSymbolExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Lightup\IFunctionPointerInvocationOperationWrapper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Lightup\IUsingDeclarationOperationWrapper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Lightup\IUsingOperationExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Lightup\LightupHelpers.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Lightup\NullableAnnotation.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Lightup\NullableContext.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Lightup\NullableContextExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Lightup\OperationKindEx.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Lightup\OperationWrapperHelper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Lightup\SemanticModelExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Options\MSBuildItemOptionNames.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Options\OptionKey.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Options\OptionKind.cs" />
Expand Down
30 changes: 0 additions & 30 deletions src/Utilities/Compiler/Lightup/IMethodSymbolExtensions.cs

This file was deleted.

11 changes: 0 additions & 11 deletions src/Utilities/Compiler/Lightup/ITypeSymbolExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,8 @@ internal static class ITypeSymbolExtensions
private static readonly Func<ITypeSymbol, NullableAnnotation> s_nullableAnnotation
= LightupHelpers.CreateSymbolPropertyAccessor<ITypeSymbol, NullableAnnotation>(typeof(ITypeSymbol), nameof(NullableAnnotation), fallbackResult: Lightup.NullableAnnotation.None);

private static readonly Func<ITypeSymbol, NullableAnnotation, ITypeSymbol> s_withNullableAnnotation
= LightupHelpers.CreateSymbolWithPropertyAccessor<ITypeSymbol, NullableAnnotation>(typeof(ITypeSymbol), nameof(NullableAnnotation), fallbackResult: Lightup.NullableAnnotation.None);

private static readonly Func<ITypeSymbol, bool> s_isNativeIntegerType
= LightupHelpers.CreateSymbolPropertyAccessor<ITypeSymbol, bool>(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);
}
}
Loading

0 comments on commit 3651e8f

Please sign in to comment.