Skip to content

Commit

Permalink
NRT
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi committed Sep 25, 2024
1 parent 788d7e6 commit 8fd0208
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading;
using Microsoft.CodeAnalysis;
Expand All @@ -33,7 +31,7 @@ public override bool TrySimplify(
ExpressionSyntax expression,
SemanticModel semanticModel,
CSharpSimplifierOptions options,
out ExpressionSyntax replacementNode,
[NotNullWhen(true)] out ExpressionSyntax? replacementNode,
out TextSpan issueSpan,
CancellationToken cancellationToken)
{
Expand Down Expand Up @@ -65,7 +63,7 @@ public override bool TrySimplify(
private static bool TryReduceExplicitName(
ExpressionSyntax expression,
SemanticModel semanticModel,
out TypeSyntax replacementNode,
[NotNullWhen(true)] out TypeSyntax? replacementNode,
out TextSpan issueSpan,
CSharpSimplifierOptions options,
CancellationToken cancellationToken)
Expand All @@ -88,7 +86,7 @@ private static bool TryReduceExplicitName(
private static bool TryReduceMemberAccessExpression(
MemberAccessExpressionSyntax memberAccess,
SemanticModel semanticModel,
out TypeSyntax replacementNode,
[NotNullWhen(true)] out TypeSyntax? replacementNode,
out TextSpan issueSpan,
CSharpSimplifierOptions options,
CancellationToken cancellationToken)
Expand Down Expand Up @@ -147,7 +145,7 @@ private static bool TryReduceMemberAccessExpression(

if (syntaxRef != null)
{
var declIdentifier = ((UsingDirectiveSyntax)syntaxRef.GetSyntax(cancellationToken)).Alias.Name.Identifier;
var declIdentifier = ((UsingDirectiveSyntax)syntaxRef.GetSyntax(cancellationToken)).Alias!.Name.Identifier;
text = declIdentifier.IsVerbatimIdentifier() ? declIdentifier.ToString()[1..] : declIdentifier.ToString();
}

Expand Down Expand Up @@ -259,7 +257,7 @@ private static bool IsReplacementCandidate(ISymbol actualSymbol, ImmutableArray<
private static bool TrySimplify(
ExpressionSyntax expression,
SemanticModel semanticModel,
out ExpressionSyntax replacementNode,
[NotNullWhen(true)] out ExpressionSyntax? replacementNode,
out TextSpan issueSpan,
CancellationToken cancellationToken)
{
Expand All @@ -273,7 +271,7 @@ private static bool TrySimplify(
static bool TrySimplifyWorker(
ExpressionSyntax expression,
SemanticModel semanticModel,
out ExpressionSyntax replacementNode,
[NotNullWhen(true)] out ExpressionSyntax? replacementNode,
out TextSpan issueSpan,
CancellationToken cancellationToken)
{
Expand Down Expand Up @@ -374,7 +372,7 @@ private static bool IsNonRemovablePartOfDynamicMethodInvocation(
var leftSymbol = semanticModel.GetSymbolInfo(memberAccess.Expression, cancellationToken).GetAnySymbol();
if (leftSymbol is INamedTypeSymbol)
{
var type = semanticModel.GetTypeInfo(memberAccess.Parent, cancellationToken).Type;
var type = semanticModel.GetTypeInfo(memberAccess.GetRequiredParent(), cancellationToken).Type;
if (type?.Kind == SymbolKind.DynamicType)
{
return true;
Expand All @@ -394,7 +392,7 @@ private static bool AccessMethodWithDynamicArgumentInsideStructConstructor(Membe
{
var constructor = memberAccess.Ancestors().OfType<ConstructorDeclarationSyntax>().SingleOrDefault();

if (constructor == null || constructor.Parent.Kind() is not (SyntaxKind.StructDeclaration or SyntaxKind.RecordStructDeclaration))
if (constructor == null || constructor.GetRequiredParent().Kind() is not (SyntaxKind.StructDeclaration or SyntaxKind.RecordStructDeclaration))
{
return false;
}
Expand All @@ -407,7 +405,7 @@ private static bool TrySimplifyMemberAccessOrQualifiedName(
ExpressionSyntax left,
ExpressionSyntax right,
SemanticModel semanticModel,
out ExpressionSyntax replacementNode,
[NotNullWhen(true)] out ExpressionSyntax? replacementNode,
out TextSpan issueSpan)
{
replacementNode = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System.Diagnostics.CodeAnalysis;
using System.Threading;
using Microsoft.CodeAnalysis.Text;

Expand All @@ -18,7 +17,7 @@ public abstract bool TrySimplify(
TSyntax syntax,
SemanticModel semanticModel,
TSimplifierOptions options,
out TSimplifiedSyntax replacementNode,
[NotNullWhen(true)] out TSimplifiedSyntax? replacementNode,
out TextSpan issueSpan,
CancellationToken cancellationToken);
}

0 comments on commit 8fd0208

Please sign in to comment.