Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private static void AnalyzeLambdaDeclaration(SyntaxNodeAnalysisContext syntaxCon
if (!lambdaOrAnonymousDelegateDeclaration.AsyncKeyword.IsKind(SyntaxKind.AsyncKeyword))
return;

var lambdaMethodSymbol = syntaxContext.SemanticModel.GetSymbolOrFirstCandidate(lambdaOrAnonymousDelegateDeclaration,
var lambdaMethodSymbol = syntaxContext.SemanticModel.GetSymbolOrBestCandidate(lambdaOrAnonymousDelegateDeclaration,
syntaxContext.CancellationToken) as IMethodSymbol;
if (lambdaMethodSymbol == null || !lambdaMethodSymbol.ReturnsVoid)
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public override void VisitUsingDirective(UsingDirectiveSyntax usingDirectiveNode
Cancellation.ThrowIfCancellationRequested();

if (usingDirectiveNode.Name == null ||
SemanticModel.GetSymbolOrFirstCandidate(usingDirectiveNode.Name, Cancellation) is not ISymbol typeOrNamespaceSymbol)
SemanticModel.GetSymbolOrBestCandidate(usingDirectiveNode.Name, Cancellation) is not ISymbol typeOrNamespaceSymbol)
{
return;
}
Expand Down Expand Up @@ -139,7 +139,7 @@ public override void VisitGenericName(GenericNameSyntax genericNameNode)
{
Cancellation.ThrowIfCancellationRequested();

if (SemanticModel.GetSymbolOrFirstCandidate(genericNameNode, Cancellation) is not ISymbol symbol)
if (SemanticModel.GetSymbolOrBestCandidate(genericNameNode, Cancellation) is not ISymbol symbol)
{
Cancellation.ThrowIfCancellationRequested();
base.VisitGenericName(genericNameNode);
Expand Down Expand Up @@ -202,8 +202,8 @@ private bool AnalyzeAccessExpressionAndDecideIfShouldVisitChildNodes(ExpressionS
{
Cancellation.ThrowIfCancellationRequested();

ISymbol? accessedMember = SemanticModel.GetSymbolOrFirstCandidate(wholeAccessExpression, Cancellation);
accessedMember ??= SemanticModel.GetSymbolOrFirstCandidate(accessMemberExpression, Cancellation);
ISymbol? accessedMember = SemanticModel.GetSymbolOrBestCandidate(wholeAccessExpression, Cancellation);
accessedMember ??= SemanticModel.GetSymbolOrBestCandidate(accessMemberExpression, Cancellation);

if (accessedMember == null)
return true;
Expand All @@ -214,7 +214,7 @@ private bool AnalyzeAccessExpressionAndDecideIfShouldVisitChildNodes(ExpressionS
return false;

expressionBeingAccessed = UnwrapAccessExpressionFromArrayAccess(expressionBeingAccessed);
var symbolBeingAccessed = SemanticModel.GetSymbolOrFirstCandidate(expressionBeingAccessed, Cancellation);
var symbolBeingAccessed = SemanticModel.GetSymbolOrBestCandidate(expressionBeingAccessed, Cancellation);

if (symbolBeingAccessed == null || symbolBeingAccessed.Equals(accessedMember.ContainingType, SymbolEqualityComparer.Default))
return !IsAllowedApi(accessedMember);
Expand All @@ -238,7 +238,7 @@ public override void VisitIdentifierName(IdentifierNameSyntax identifierNode)
{
Cancellation.ThrowIfCancellationRequested();

if (SemanticModel.GetSymbolOrFirstCandidate(identifierNode, Cancellation) is not ISymbol symbol)
if (SemanticModel.GetSymbolOrBestCandidate(identifierNode, Cancellation) is not ISymbol symbol)
return;

Cancellation.ThrowIfCancellationRequested();
Expand All @@ -249,7 +249,7 @@ public override void VisitQualifiedName(QualifiedNameSyntax qualifiedName)
{
Cancellation.ThrowIfCancellationRequested();

if (SemanticModel.GetSymbolOrFirstCandidate(qualifiedName, Cancellation) is not ISymbol symbol)
if (SemanticModel.GetSymbolOrBestCandidate(qualifiedName, Cancellation) is not ISymbol symbol)
{
base.VisitQualifiedName(qualifiedName);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ public override bool VisitUsingStatement(UsingStatementSyntax node)
public override bool VisitObjectCreationExpression(ObjectCreationExpressionSyntax node)
{
var semanticModel = _semanticModelGetter(node.SyntaxTree);
var typeSymbol = semanticModel?.GetSymbolOrFirstCandidate(node.Type, _cancellation) as ITypeSymbol;
var typeSymbol = semanticModel?.GetSymbolOrBestCandidate(node.Type, _cancellation) as ITypeSymbol;
return IsPXConnectionScope(typeSymbol);
}

public override bool VisitImplicitObjectCreationExpression(ImplicitObjectCreationExpressionSyntax node)
{
var semanticModel = _semanticModelGetter(node.SyntaxTree);
var constructor = semanticModel?.GetSymbolOrFirstCandidate(node, _cancellation) as IMethodSymbol;
var constructor = semanticModel?.GetSymbolOrBestCandidate(node, _cancellation) as IMethodSymbol;

if (constructor?.ContainingType == null || constructor.MethodKind != MethodKind.Constructor)
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private void CheckVariableOrParameterTypeIsNotTask(TypeSyntax? typeNode)
if (typeNode == null)
return;

var variableType = SemanticModel.GetSymbolOrFirstCandidate(typeNode, Cancellation) as ITypeSymbol;
var variableType = SemanticModel.GetSymbolOrBestCandidate(typeNode, Cancellation) as ITypeSymbol;

if (variableType == null || !IsTaskType(variableType))
return;
Expand Down Expand Up @@ -159,7 +159,7 @@ private void CheckTypeMemberReturningTaskHasTaskReturnType(ExpressionSyntax? ret
{
if (containingMethodOrLocalFunction is AnonymousFunctionExpressionSyntax lambdaDeclaration)
{
var lambdaSymbol = SemanticModel.GetSymbolOrFirstCandidate(lambdaDeclaration, Cancellation) as IMethodSymbol;
var lambdaSymbol = SemanticModel.GetSymbolOrBestCandidate(lambdaDeclaration, Cancellation) as IMethodSymbol;
return lambdaSymbol?.ReturnType;
}

Expand All @@ -174,7 +174,7 @@ private void CheckTypeMemberReturningTaskHasTaskReturnType(ExpressionSyntax? ret
if (returnTypeNode == null)
return null;

var returnTypeSymbol = SemanticModel.GetSymbolOrFirstCandidate(returnTypeNode, Cancellation) as ITypeSymbol;
var returnTypeSymbol = SemanticModel.GetSymbolOrBestCandidate(returnTypeNode, Cancellation) as ITypeSymbol;
return returnTypeSymbol;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private void AnalyzePXExceptionAndPXExceptionInfoConstructorInvocations(SyntaxNo
if (!isLocalizableException && !isPXExceptionInfo)
return;

var symbol = syntaxContext.SemanticModel.GetSymbolOrFirstCandidate(constructorCall, syntaxContext.CancellationToken);
var symbol = syntaxContext.SemanticModel.GetSymbolOrBestCandidate(constructorCall, syntaxContext.CancellationToken);

if (symbol is not IMethodSymbol constructor)
return;
Expand Down Expand Up @@ -116,7 +116,7 @@ private void AnalyzePXExceptionChainedConstructorCall(SyntaxNodeAnalysisContext

foreach (ConstructorInitializerSyntax constructorCall in baseOrThisConstructorCalls)
{
var symbol = syntaxContext.SemanticModel.GetSymbolOrFirstCandidate(constructorCall, syntaxContext.CancellationToken);
var symbol = syntaxContext.SemanticModel.GetSymbolOrBestCandidate(constructorCall, syntaxContext.CancellationToken);

if (symbol is not IMethodSymbol constructorSymbol)
continue;
Expand Down Expand Up @@ -145,9 +145,9 @@ private void AnalyzePXExceptionChainedConstructorCall(SyntaxNodeAnalysisContext

for (int argIndex = 0; argIndex < args.Arguments.Count; argIndex++)
{
IParameterSymbol mappedParameter = argumentsToParametersMapping.Value.GetMappedParameter(constructor, argIndex);
IParameterSymbol? mappedParameter = argumentsToParametersMapping.Value.GetMappedParameter(constructor, argIndex);

if (parametersWithLocalizableText.Contains(mappedParameter.Name, StringComparer.Ordinal))
if (mappedParameter != null && parametersWithLocalizableText.Contains(mappedParameter.Name, StringComparer.Ordinal))
{
var argument = args.Arguments[argIndex];
return argument.Expression;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,11 @@ private void FilterReassignedParameters(NonCapturableElementsInfo nonCapturableE
continue;

var mappedParameter = argumentsToParametersMapping.Value.GetMappedParameter(calledMethod, argument.Index);
nonCapturableParametersOfCalledMethodFromCallArgs.Add(new PassedParameter(mappedParameter.Name, capturedTypes));

if (mappedParameter != null)
{
nonCapturableParametersOfCalledMethodFromCallArgs.Add(new PassedParameter(mappedParameter.Name, capturedTypes));
}
}

return nonCapturableParametersOfCalledMethodFromCallArgs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private static (LongOperationDelegateType Type, IMethodSymbol Method)? GetLongOp
{
case DelegateNames.Processing.SetProcessDelegate:
case DelegateNames.Processing.SetAsyncProcessDelegate:
var setDelegateSymbol = semanticModel.GetSymbolOrFirstCandidate(methodAccessNode, cancellationToken) as IMethodSymbol;
var setDelegateSymbol = semanticModel.GetSymbolOrBestCandidate(methodAccessNode, cancellationToken) as IMethodSymbol;

if (setDelegateSymbol != null && setDelegateSymbol.ContainingType.ConstructedFrom.InheritsFromOrEquals(pxContext.PXProcessingBase.Type))
return (LongOperationDelegateType.ProcessingDelegate, setDelegateSymbol);
Expand All @@ -61,7 +61,7 @@ private static (LongOperationDelegateType Type, IMethodSymbol Method)? GetLongOp
case DelegateNames.Async.StartOperation:
case DelegateNames.Async.StartAsyncOperation:
case DelegateNames.Async.Await:
var longRunDelegate = semanticModel.GetSymbolOrFirstCandidate(methodAccessNode, cancellationToken) as IMethodSymbol;
var longRunDelegate = semanticModel.GetSymbolOrBestCandidate(methodAccessNode, cancellationToken) as IMethodSymbol;

if (longRunDelegate == null)
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public override void Analyze(SymbolAnalysisContext context, PXContext pxContext,

foreach (GenericNameSyntax baseClassTypeNode in baseClassesTypeNodes)
{
var baseClassTypeSymbol = semanticModel.GetSymbolOrFirstCandidate(baseClassTypeNode, context.CancellationToken) as INamedTypeSymbol;
var baseClassTypeSymbol = semanticModel.GetSymbolOrBestCandidate(baseClassTypeNode, context.CancellationToken) as INamedTypeSymbol;
Location? location = GetLocationFromBaseClassTypeNode(baseClassTypeNode, baseClassTypeSymbol, declaredPrimaryDacType);

if (location != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override void VisitObjectCreationExpression(ObjectCreationExpressionSynta
{
_context.CancellationToken.ThrowIfCancellationRequested();

if (node.Type == null || _semanticModel.GetSymbolOrFirstCandidate(node.Type, _context.CancellationToken) is not ITypeSymbol typeSymbol)
if (node.Type == null || _semanticModel.GetSymbolOrBestCandidate(node.Type, _context.CancellationToken) is not ITypeSymbol typeSymbol)
{
base.VisitObjectCreationExpression(node);
return;
Expand All @@ -53,7 +53,7 @@ public override void VisitImplicitObjectCreationExpression(ImplicitObjectCreatio
{
_context.CancellationToken.ThrowIfCancellationRequested();

var constructor = _semanticModel.GetSymbolOrFirstCandidate(node, _context.CancellationToken) as IMethodSymbol;
var constructor = _semanticModel.GetSymbolOrBestCandidate(node, _context.CancellationToken) as IMethodSymbol;

if (constructor?.ContainingType == null || constructor.MethodKind != MethodKind.Constructor)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public Rewriter(PXContext pxContext, Document document, SemanticModel semanticMo
if (_generator == null)
return base.VisitObjectCreationExpression(node);

var graphTypeSymbol = _semanticModel.GetSymbolOrFirstCandidate(node.Type, _cancellation) as ITypeSymbol;
var graphTypeSymbol = _semanticModel.GetSymbolOrBestCandidate(node.Type, _cancellation) as ITypeSymbol;
var createInstanceCallNode = GeneratePXGraphCreateInstanceCall(graphTypeSymbol);

return createInstanceCallNode ?? base.VisitObjectCreationExpression(node);
Expand All @@ -100,7 +100,7 @@ public Rewriter(PXContext pxContext, Document document, SemanticModel semanticMo
if (_generator == null)
return base.VisitImplicitObjectCreationExpression(node);

var constructor = _semanticModel.GetSymbolOrFirstCandidate(node, _cancellation) as IMethodSymbol;
var constructor = _semanticModel.GetSymbolOrBestCandidate(node, _cancellation) as IMethodSymbol;

if (constructor?.ContainingType == null || constructor.MethodKind != MethodKind.Constructor)
return base.VisitImplicitObjectCreationExpression(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private void AnalyseCaseWithNoAvailableExistingGraphs(CodeBlockAnalysisContext c

private HashSet<ISymbol> GetDifferentSymbolsFromCallArgs(SemanticModel semanticModel, List<ExpressionSyntax> bqlSelectGraphArgNodes,
CancellationToken cancellation) =>
bqlSelectGraphArgNodes.Select(graphArgSyntax => semanticModel.GetSymbolOrFirstCandidate(graphArgSyntax, cancellation))
bqlSelectGraphArgNodes.Select(graphArgSyntax => semanticModel.GetSymbolOrBestCandidate(graphArgSyntax, cancellation))
.Where(graphArgSymbol => graphArgSymbol != null && graphArgSymbol is not (IPropertySymbol or IFieldSymbol))
.ToHashSet(SymbolEqualityComparer.Default)!;

Expand All @@ -150,7 +150,7 @@ private Dictionary<ISymbol, List<SyntaxNode>> GetGraphSymbolsUsages(CSharpSyntax

foreach (var subNode in nodesToVisit)
{
var symbol = semanticModel.GetSymbolOrFirstCandidate(subNode, cancellation);
var symbol = semanticModel.GetSymbolOrBestCandidate(subNode, cancellation);

if (symbol != null && existingGraphs.Contains(symbol, SymbolEqualityComparer.Default))
{
Expand Down Expand Up @@ -183,7 +183,7 @@ private void AnalyzeGraphArgumentOfBqlQuery(CodeBlockAnalysisContext context, PX
return;
}

var localVar = context.SemanticModel.GetSymbolOrFirstCandidate(graphArgSyntax, context.CancellationToken) as ILocalSymbol;
var localVar = context.SemanticModel.GetSymbolOrBestCandidate(graphArgSyntax, context.CancellationToken) as ILocalSymbol;

// Do not report and do not suggest to change the graph if it is used somewhere else to avoid disruptive side effects in the business logic
// This includes fields and properties that store graph or a graph extension. The analysis of type members that store graphs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public override void VisitInvocationExpression(InvocationExpressionSyntax node)
return;
}

var methodSymbol = _semanticModel.GetSymbolOrFirstCandidate(node, _cancellation) as IMethodSymbol;
var methodSymbol = _semanticModel.GetSymbolOrBestCandidate(node, _cancellation) as IMethodSymbol;

if (IsBqlSelectOrSearch(methodSymbol))
{
Expand Down Expand Up @@ -85,7 +85,7 @@ private bool ArgumentIsPropertyOrField(ExpressionSyntax bqlCallGraphArg)

private bool ArgumentIsPropertyOrField(IdentifierNameSyntax identifier)
{
var graphArgSymbol = _semanticModel.GetSymbolOrFirstCandidate(identifier, _cancellation);
var graphArgSymbol = _semanticModel.GetSymbolOrBestCandidate(identifier, _cancellation);
return graphArgSymbol is IPropertySymbol or IFieldSymbol;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private static bool IsSeeAlsoWithCrefAttributeToBaseMethod(SemanticModel semanti
if (attributes.Value[i] is not XmlCrefAttributeSyntax crefAttribute)
continue;

var referencedSymbol = semanticModel.GetSymbolOrFirstCandidate(crefAttribute.Cref, cancellation);
var referencedSymbol = semanticModel.GetSymbolOrBestCandidate(crefAttribute.Cref, cancellation);

if (DoesReferencedSymbolPointToBaseMethod(referencedSymbol, baseMethod))
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public async Task Static_Lambdas_Have_StaticSymbols(string text)

foreach (var lambda in lambdas)
{
var symbol = semanticModel.GetSymbolOrFirstCandidate(lambda, default) as IMethodSymbol;
var symbol = semanticModel.GetSymbolOrBestCandidate(lambda, default) as IMethodSymbol;
symbol.Should().NotBeNull();

symbol!.MethodKind.Should().Be(MethodKind.LambdaMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,15 @@ public ArgumentsToParametersMapping(int[] parametersMapping)
_length = parametersMapping.Length;
}

public IParameterSymbol GetMappedParameter(IMethodSymbol methodSymbol, int argIndex)
public IParameterSymbol? GetMappedParameter(IMethodSymbol methodSymbol, int argIndex)
{
methodSymbol.ThrowOnNull();
int parameterIndex = GetMappedParameterPosition(argIndex);

// In case of a broken solution we can get index out of range error because of a method node being mapped to a wrong symbol
if (parameterIndex >= methodSymbol.Parameters.Length)
return null;

return methodSymbol.Parameters[parameterIndex];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#nullable enable

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Runtime.CompilerServices;

Expand All @@ -28,6 +28,14 @@ public static bool IsReadOnly(this ISymbol symbol) =>
_ => false
};

public static ImmutableArray<IParameterSymbol>? Parameters(this ISymbol symbol) =>
symbol.CheckIfNull() switch
{
IMethodSymbol method => method.Parameters,
IPropertySymbol property => property.Parameters,
_ => null
};

public static bool IsReadOnly(this ITypeSymbol typeSymbol)
{
typeSymbol.ThrowOnNull();
Expand Down
Loading