2 implementations of Syntax
Microsoft.CodeAnalysis (1)
Operations\Operation.cs (1)
70public SyntaxNode Syntax { get; }
Microsoft.CodeAnalysis.CSharp.Emit3.UnitTests (1)
Semantics\CollectionExpressionTests.cs (1)
27086SyntaxNode IOperation.Syntax => throw null;
1001 references to Syntax
Aspire.Hosting.Analyzers (1)
AppHostAnalyzer.cs (1)
131if (argumentOperation?.Syntax is not ArgumentSyntax routePatternArgumentSyntax ||
ConfigurationSchemaGenerator (2)
RuntimeSource\Configuration.Binder\Specs\InterceptorInfo.cs (2)
173if (invocation.Syntax is not InvocationExpressionSyntax { Expression: MemberAccessExpressionSyntax memberAccessExprSyntax }) 179SyntaxTree operationSyntaxTree = invocation.Syntax.SyntaxTree;
ILLink.RoslynAnalyzer (18)
COMAnalyzer.cs (1)
55 operationContext.Operation.Syntax.GetLocation (), targetMethod.GetDisplayName ()));
DataFlow\LocalDataFlowVisitor.cs (7)
104 $"{OwningSymbol.GetType ()}: {branchValueOperation.Syntax.GetLocation ().GetLineSpan ()}"); 112 $"{OwningSymbol.GetType ()}: {branchValueOperation.Syntax.GetLocation ().GetLineSpan ()}"); 205 $"{local.ContainingSymbol.GetType ()}: {localReference.Syntax.GetLocation ().GetLineSpan ()}"); 452 $"{operation.Syntax.GetLocation ().GetLineSpan ()}"); 454 $"{operation.Syntax.GetLocation ().GetLineSpan ()}"); 473 $"{operation.Syntax.GetLocation ().GetLineSpan ()}"); 475 $"{operation.Syntax.GetLocation ().GetLineSpan ()}");
DataFlow\UnexpectedOperationHandler.cs (1)
47 throw new NotImplementedException ($"Unexpected operation type {operation.GetType ()}: {operation.Syntax.GetLocation ().GetLineSpan ()}");
TrimAnalysis\FeatureCheckReturnValuePattern.cs (1)
35 var diagnosticContext = new DiagnosticContext (Operation.Syntax.GetLocation (), reportDiagnostic);
TrimAnalysis\TrimAnalysisAssignmentPattern.cs (1)
58 var diagnosticContext = new DiagnosticContext (Operation.Syntax.GetLocation (), reportDiagnostic);
TrimAnalysis\TrimAnalysisFieldAccessPattern.cs (1)
49 DiagnosticContext diagnosticContext = new (Operation.Syntax.GetLocation (), reportDiagnostic);
TrimAnalysis\TrimAnalysisGenericInstantiationPattern.cs (1)
51 var location = Operation.Syntax.GetLocation ();
TrimAnalysis\TrimAnalysisMethodCallPattern.cs (1)
74 var location = Operation.Syntax.GetLocation ();
TrimAnalysis\TrimAnalysisReflectionAccessPattern.cs (1)
48 var location = Operation.Syntax.GetLocation ();
TrimAnalysis\TrimDataFlowAnalysis.cs (3)
96 var method = op.Syntax.FirstAncestorOrSelf<MethodDeclarationSyntax> (); 116 TraceWriteLine (firstBlockOp.Syntax.ToString ()); 118 TraceWriteLine (branchOp.Syntax.ToString ());
Microsoft.Analyzers.Extra (21)
AsyncCallInsideUsingBlockAnalyzer.cs (1)
123Diagnostic.Create(DiagDescriptors.AsyncCallInsideUsingBlock, invocation.Syntax.GetLocation());
CallAnalysis\Arrays.cs (2)
101static void HandleMethod(OperationAnalysisContext context, IInvocationOperation op) => HandleSuspectType(context, (INamedTypeSymbol)op.TargetMethod.ReturnType, op.Syntax.GetLocation()); 103static void HandleConstructor(OperationAnalysisContext context, IObjectCreationOperation op) => HandleSuspectType(context, (INamedTypeSymbol)op.Type!, op.Syntax.GetLocation());
CallAnalysis\Fixers\LegacyLoggingFixer.cs (5)
404var type = e.SemanticModel?.GetTypeInfo(e.Syntax).Type!; 492loggerSyntaxNode = arg.Syntax; 502argList.Add(a.Syntax.WithoutTrivia()); 509argList.Add(e.Syntax.WithoutTrivia()); 514argList.Add(arg.Syntax.WithoutTrivia());
CallAnalysis\Fixers\LegacyLoggingFixer.FixDetails.cs (1)
71var argName = operation.Syntax.GetLastToken().Text;
CallAnalysis\LegacyCollection.cs (1)
33var diagnostic = Diagnostic.Create(DiagDescriptors.LegacyCollection, op.Syntax.GetLocation());
CallAnalysis\LegacyLogging.cs (1)
38var diagnostic = Diagnostic.Create(DiagDescriptors.LegacyLogging, op.Syntax.GetLocation());
CallAnalysis\Split.cs (1)
28var diagnostic = Diagnostic.Create(DiagDescriptors.Split, op.Syntax.GetLocation());
CallAnalysis\StartsEndsWith.cs (1)
59var diagnostic = Diagnostic.Create(DiagDescriptors.StartsEndsWith, op.Syntax.GetLocation(), op.TargetMethod.Name);
CallAnalysis\StaticTime.cs (2)
52var diagnostic = Diagnostic.Create(DiagDescriptors.StaticTime, op.Syntax.GetLocation()); 58var diagnostic = Diagnostic.Create(DiagDescriptors.StaticTime, op.Syntax.GetLocation());
CallAnalysis\ValueTuple.cs (2)
42var diagnostic = Diagnostic.Create(DiagDescriptors.ValueTuple, op.Syntax.GetLocation()); 48var diagnostic = Diagnostic.Create(DiagDescriptors.ValueTuple, op.Syntax.GetLocation());
CoalesceAnalyzer.cs (2)
52var diagnostic = Diagnostic.Create(DiagDescriptors.CoalesceAssignment, op.Syntax.GetLocation()); 79var diagnostic = Diagnostic.Create(DiagDescriptors.Coalesce, op.Syntax.GetLocation());
ConditionalAccessAnalyzer.cs (1)
111var diagnostic = Diagnostic.Create(DiagDescriptors.ConditionalAccess, op.Syntax.GetLocation());
UsingToStringInLoggersAnalyzer.cs (1)
69yield return Diagnostic.Create(DiagDescriptors.UsingToStringInLoggers, arg.Syntax.GetLocation());
Microsoft.Analyzers.Local (5)
CallAnalysis\Throws.cs (4)
35if (op.Syntax.IsKind(SyntaxKind.ThrowStatement)) 39op.Syntax.GetLocation(), 44else if (op.Syntax.IsKind(SyntaxKind.ThrowExpression)) 48var throwExpression = (ThrowExpressionSyntax)op.Syntax;
CallAnalysis\ToInvariantString.cs (1)
51var diagnostic = Diagnostic.Create(DiagDescriptors.ToInvariantString, op.Syntax.GetLocation());
Microsoft.AspNetCore.Analyzers (4)
BuildServiceProviderAnalyzer.cs (1)
33serviceItem.Operation.Syntax.GetLocation(),
UseAuthorizationAnalyzer.cs (2)
51middlewareItem.Operation.Syntax.GetLocation(), 71useAuthorizationItem.Operation.Syntax.GetLocation(),
UseMvcAnalyzer.cs (1)
45middlewareItem.Operation.Syntax.GetLocation(),
Microsoft.AspNetCore.App.Analyzers (21)
Authorization\AddAuthorizationBuilderAnalyzer.cs (1)
62AddDiagnosticInformation(context, invocation.Syntax.GetLocation());
Http\HeaderDictionaryAddAnalyzer.cs (1)
38AddDiagnosticWarning(context, invocation.Syntax.GetLocation());
Http\HeaderDictionaryIndexerAnalyzer.cs (1)
41AddDiagnosticWarning(context, propertyReference.Syntax.GetLocation(), indexerValue, propertyName);
Http\RequestDelegateReturnTypeAnalyzer.cs (2)
40AddDiagnosticWarning(context, methodReference.Syntax.GetLocation(), returnType); 66AddDiagnosticWarning(context, anonymousFunction.Syntax.GetLocation(), returnType);
RenderTreeBuilder\RenderTreeBuilderAnalyzer.cs (3)
43if (!argument.Value.Syntax.IsKind(SyntaxKind.NumericLiteralExpression)) 47argument.Syntax.GetLocation(), 48argument.Syntax.ToString()));
RouteHandlers\DetectMisplacedLambdaAttribute.cs (1)
41var location = lambda.Syntax.GetLocation();
RouteHandlers\DisallowReturningActionResultFromMapMethods.cs (1)
83returnOperation.Syntax.GetLocation(),
RouteHandlers\RouteHandlerAnalyzer.cs (5)
110DisallowReturningActionResultFromMapMethods(in context, wellKnownTypes, invocation, lambda, delegateCreation.Syntax); 140delegateCreation.Syntax); 151delegateCreation.Syntax); 165delegateCreation.Syntax); 184if (argumentOperation?.Syntax is not ArgumentSyntax routePatternArgumentSyntax ||
src\Shared\Roslyn\CodeAnalysisExtensions.cs (2)
183return GetReceiverType(invocation.Instance.Syntax, invocation.SemanticModel, cancellationToken); 190return GetReceiverType(firstArg.Value.Syntax, invocation.SemanticModel, cancellationToken);
WebApplicationBuilder\WebApplicationBuilderAnalyzer.cs (4)
258var location = operation.Syntax.GetLocation(); 280var methodName = operation.Syntax 301location = Location.Create(operation.Syntax.SyntaxTree, targetSpan); 368var arguments = argument?.Syntax as ArgumentSyntax;
Microsoft.AspNetCore.Components.Analyzers (3)
ComponentParameterUsageAnalyzer.cs (1)
107propertyReference.Syntax.GetLocation(),
InternalUsageAnalyzer.cs (2)
139context.Operation.Syntax.GetLocation(), 149context.Operation.Syntax.GetLocation(),
Microsoft.AspNetCore.Components.SdkAnalyzers (3)
ComponentParameterUsageAnalyzer.cs (1)
107propertyReference.Syntax.GetLocation(),
InternalUsageAnalyzer.cs (2)
139context.Operation.Syntax.GetLocation(), 149context.Operation.Syntax.GetLocation(),
Microsoft.AspNetCore.Http.RequestDelegateGenerator (13)
StaticRouteHandlerModel\Endpoint.cs (9)
24InterceptableLocation = semanticModel.GetInterceptableLocation((InvocationExpressionSyntax)operation.Syntax)!; 31Diagnostics.Add(Diagnostic.Create(DiagnosticDescriptors.UnableToResolveMethod, Operation.Syntax.GetLocation())); 36Response.EmitRequiredDiagnostics(Diagnostics, Operation.Syntax.GetLocation()); 58parameterSymbol.EmitRequiredDiagnostics(Diagnostics, Operation.Syntax.GetLocation()); 79Operation.Syntax.GetLocation(), 156var memberAccessorExpression = ((MemberAccessExpressionSyntax)((InvocationExpressionSyntax)operation.Syntax).Expression); 164var lineSpan = operation.Syntax.SyntaxTree.GetLineSpan(invocationNameSpan); 166var filePath = operation.Syntax.SyntaxTree.GetInterceptorFilePath(operation.SemanticModel?.Compilation.Options.SourceReferenceResolver); 173var syntax = (InvocationExpressionSyntax)operation.Syntax;
StaticRouteHandlerModel\EndpointParameter.cs (4)
115var location = endpoint.Operation.Syntax.GetLocation(); 151var location = endpoint.Operation.Syntax.GetLocation(); 164var location = endpoint.Operation.Syntax.GetLocation(); 462var location = endpoint.Operation.Syntax.GetLocation();
Microsoft.AspNetCore.Mvc.Analyzers (5)
AvoidHtmlPartialAnalyzer.cs (2)
33context.Operation.Syntax.GetLocation(), 40context.Operation.Syntax.GetLocation(),
src\Shared\Roslyn\CodeAnalysisExtensions.cs (2)
183return GetReceiverType(invocation.Instance.Syntax, invocation.SemanticModel, cancellationToken); 190return GetReceiverType(firstArg.Value.Syntax, invocation.SemanticModel, cancellationToken);
TagHelpersInCodeBlocksAnalyzer.cs (1)
88capturedDiagnosticLocations.Add(parent.Syntax.GetLocation());
Microsoft.AspNetCore.Mvc.Api.Analyzers (6)
ApiActionsDoNotRequireExplicitModelValidationCheckAnalyzer.cs (3)
114var returnStatementSyntax = returnOperation.Syntax; 117ifOperation.Syntax.GetLocation(), 124ifOperation.Syntax.GetLocation(),
ApiConventionAnalyzer.cs (1)
53var location = actualMetadata.ReturnOperation.ReturnedValue.Syntax.GetLocation();
src\Shared\Roslyn\CodeAnalysisExtensions.cs (2)
183return GetReceiverType(invocation.Instance.Syntax, invocation.SemanticModel, cancellationToken); 190return GetReceiverType(firstArg.Value.Syntax, invocation.SemanticModel, cancellationToken);
Microsoft.CodeAnalysis (253)
DiagnosticAnalyzer\AnalysisContextInfo.cs (2)
48this(compilation: compilation, operation: operation, symbol: null, file: new SourceOrAdditionalFile(operation.Syntax.SyntaxTree), node: operation.Syntax)
DiagnosticAnalyzer\AnalyzerDriver.cs (1)
2757? operationsToAnalyze.WhereAsArray(operation => analysisScope.ShouldAnalyze(operation.Syntax))
DiagnosticAnalyzer\AnalyzerExecutor.cs (4)
1114diagReporter.FilterSpanForLocalDiagnostics = operation.Syntax.FullSpan; 1480if (operation.Syntax != null && _shouldSkipAnalysisOnGeneratedCode(analyzer) && 1481_isGeneratedCodeLocation(operation.Syntax.SyntaxTree, operation.Syntax.Span, cancellationToken))
DiagnosticAnalyzer\DiagnosticAnalysisContext.cs (3)
1296filterTree: operationBlocks[0].Syntax.SyntaxTree, filterSpan: null, isGeneratedCode: false, cancellationToken) 1440filterTree: operationBlocks[0].Syntax.SyntaxTree, filterSpan: null, isGeneratedCode: false, cancellationToken) 1853FilterTree = operation.Syntax.SyntaxTree;
Operations\ControlFlowGraphBuilder.cs (229)
1412return result ?? MakeInvalidOperation(originalOperation.Syntax, originalOperation.Type, ImmutableArray<IOperation>.Empty); 1672CaptureResultIfNotAlready(operation.Syntax, captureId, result); 1912AddStatement(new FlowCaptureOperation(captureId, operationOpt.Syntax, operationOpt) 2104return PopStackFrame(frame, new SimpleAssignmentOperation(operation.IsRef, PopOperand(), value, null, operation.Syntax, operation.Type, operation.GetConstantValue(), IsImplicit(operation))); 2116syntax: operation.Syntax, type: operation.Type, isImplicit: IsImplicit(operation))); 2127operation.Syntax, operation.Type, IsImplicit(operation)); 2138operation.Syntax, operation.Type, IsImplicit(operation)); 2149operation.Syntax, operation.Type, IsImplicit(operation)); 2232semanticModel: null, operation.Syntax, operation.Type, operation.GetConstantValue(), IsImplicit(operation))); 2246semanticModel: null, operation.Syntax, operation.Type, IsImplicit(operation)); 2258semanticModel: null, operation.Syntax, operation.Type, operation.GetConstantValue(), IsImplicit(operation)); 2384AddStatement(new FlowCaptureOperation(resultId, binOp.Syntax, OperationCloner.CloneOperation(capturedRight))); 2390AddStatement(new FlowCaptureOperation(resultId, binOp.Syntax, OperationCloner.CloneOperation(capturedLeft))); 2402semanticModel: null, operand.Syntax, operand.Type, constantValue: null, isImplicit: true); 2434AddStatement(new FlowCaptureOperation(resultId, binOp.Syntax, new LiteralOperation(semanticModel: null, left.Syntax, booleanType, constantValue, isImplicit: true))); 2443AddStatement(new FlowCaptureOperation(resultId, binOp.Syntax, condition)); 2450condition = new FlowCaptureReferenceOperation(resultId, binOp.Syntax, booleanType, constantValue: null); 2453semanticModel: null, binOp.Syntax, binOp.Type, binOp.GetConstantValue(), isImplicit: true); 2459semanticModel: null, operand.Syntax, type, constantValue, isImplicit: true); 2505semanticModel: null, condition.Syntax, booleanType, constantValue: null, isImplicit: true); 2530AddStatement(new FlowCaptureOperation(resultId, binOp.Syntax, resultFromLeft)); 2538AddStatement(new FlowCaptureOperation(resultId, binOp.Syntax, 2549binOp.Syntax, 2608semanticModel: null, condition.Syntax, unaryOperatorMethod.ReturnType, constantValue: null, isImplicit: true); 2619AddStatement(new FlowCaptureOperation(resultId, binOp.Syntax, OperationCloner.CloneOperation(capturedLeft))); 2628AddStatement(new FlowCaptureOperation(resultId, binOp.Syntax, 2639binOp.Syntax, 2681CaptureResultIfNotAlready(condition.RightOperand.Syntax, captureId, resultFromRight); 2693SyntaxNode leftSyntax = (lazyFallThrough!.GetSingletonPredecessorOrDefault() != null ? condition.LeftOperand : condition).Syntax; 2739lastUnary.OperatorMethod, lastUnary.ConstrainedToType, semanticModel: null, lastUnary.Syntax, 2742operatorMethod: null, constrainedToType: null, semanticModel: null, condition.Syntax, 2987SyntaxNode valueSyntax = operationValue.Syntax; 3078AddStatement(new FlowCaptureOperation(resultCaptureId, operation.Value.Syntax, convertedTestExpression)); 3121AddStatement(new FlowCaptureOperation(valueCaptureId, locationCapture.Syntax, locationCapture)); 3185operation.Target.Syntax, 3200operation.Syntax, 3219AddStatement(new FlowCaptureOperation(intermediateValueCaptureId, whenNullValue.Syntax, whenNullValue)); 3224operation.Syntax, 3234syntax: operation.Syntax, 3252AddStatement(new FlowCaptureOperation(resultCaptureId, operation.Syntax, OperationCloner.CloneOperation(valueCapture))); 3268operation.Syntax, operation.Type, constantValue: operation.GetConstantValue(), isImplicit: true); 3276AddStatement(new FlowCaptureOperation(resultCaptureId, operation.Syntax, whenNullAssignment)); 3291semanticModel: null, child.Syntax, type, 3318return new IsNullOperation(operand.Syntax, operand, 3344ImmutableArray<IArgumentOperation>.Empty, semanticModel: null, value.Syntax, 3417result = new ExpressionStatementOperation(result, semanticModel: null, expressionStatement.Syntax, 3433AddStatement(new FlowCaptureOperation(resultCaptureId, currentConditionalAccess.WhenNotNull.Syntax, 3438CaptureResultIfNotAlready(currentConditionalAccess.WhenNotNull.Syntax, resultCaptureId, 3452SyntaxNode defaultValueSyntax = (operation.Operation == testExpression ? testExpression : operation).Syntax; 3530SyntaxNode testExpressionSyntax = testExpression.Syntax; 3570return FinishVisitingStatement(operation, new ExpressionStatementOperation(underlying, semanticModel: null, operation.Syntax, IsImplicit(operation))); 3790SyntaxNode syntax = exceptionDeclarationOrExpression.Syntax; 3835AddStatement(new ReturnOperation(returnedValue, OperationKind.YieldReturn, semanticModel: null, operation.Syntax, IsImplicit(operation))); 3932return new NoneOperation(children: ImmutableArray<IOperation>.Empty, semanticModel: null, operation.Syntax, constantValue: null, isImplicit: true, type: null); 4019processResource(new LocalReferenceOperation(localSymbol, isDeclaration: false, semanticModel: null, declarator.Syntax, localSymbol.Type, 4081AddStatement(new FlowCaptureOperation(captureId, resource.Syntax, resource)); 4129AddStatement(new FlowCaptureOperation(captureId, resource.Syntax, resource)); 4190args, semanticModel: null, value.Syntax, 4195return new AwaitOperation(invocation, semanticModel: null, value.Syntax, _compilation.GetSpecialType(SpecialType.System_Void), isImplicit: true); 4215semanticModel: null, operand.Syntax, iDisposable, constantValue, isImplicit: true); 4247syntax: lockObject.Syntax, 4263operation.Syntax, 4350lockedValue.Syntax, 4352semanticModel: null, lockedValue.Syntax, 4368lockTaken = new LocalReferenceOperation(lockStatement.LockTakenSymbol, isDeclaration: true, semanticModel: null, lockedValue.Syntax, 4378lockedValue.Syntax, 4386lockedValue.Syntax, 4388semanticModel: null, lockedValue.Syntax, 4409IOperation condition = new LocalReferenceOperation(lockStatement.LockTakenSymbol, isDeclaration: false, semanticModel: null, lockedValue.Syntax, 4433lockedValue.Syntax, 4435semanticModel: null, lockedValue.Syntax, 4564operand.Syntax, targetType, constantValue: null, isImplicit: true); 4585AddStatement(new FlowCaptureOperation(localCopyCaptureId, operation.Collection.Syntax, collection)); 4587collection = new FlowCaptureReferenceOperation(localCopyCaptureId, operation.Collection.Syntax, collection.Type, constantValue: null); 4593IOperation invocation = makeInvocation(operation.Collection.Syntax, 4599AddStatement(new FlowCaptureOperation(enumeratorCaptureId, operation.Collection.Syntax, invocation)); 4601result = new FlowCaptureReferenceOperation(enumeratorCaptureId, operation.Collection.Syntax, info.GetEnumeratorMethod.ReturnType, constantValue: null); 4607result = new InvalidOperation(ImmutableArray<IOperation>.Empty, semanticModel: null, operation.Collection.Syntax, 4622return new AwaitOperation(moveNext, semanticModel: null, operation.Syntax, _compilation.GetSpecialType(SpecialType.System_Boolean), isImplicit: true); 4644operation.LoopControlVariable.Syntax, 4667declarator.Syntax, 4673declarator.Syntax, 4684operation.LoopControlVariable.Syntax, operation.LoopControlVariable.Type, 4689current, semanticModel: null, operation.LoopControlVariable.Syntax, 4697return makeInvocation(instance.Syntax, method, method.IsStatic ? null : instance, arguments); 4785operation.LoopControlVariable.Syntax, loopObject.Type, 4802return MakeInvalidOperation(operation.LimitValue.Syntax, booleanType, builder.ToImmutableAndFree()); 4827semanticModel: null, isInitialization ? value.Syntax : syntax, isImplicit: true); 4834semanticModel: null, operation.LimitValue.Syntax, method.ReturnType, 4873IOperation condition = tryCallObjectForLoopControlHelper(operation.LoopControlVariable.Syntax, 4948isUp = new LiteralOperation(semanticModel: null, stepValue.Syntax, booleanType, constantValue: ConstantValue.Create(false), isImplicit: true); 4950AddStatement(new FlowCaptureOperation(positiveFlagId, isUp.Syntax, isUp)); 4956IOperation literal = new LiteralOperation(semanticModel: null, stepValue.Syntax, stepValue.Type, 4970stepValue.Syntax, 4975AddStatement(new FlowCaptureOperation(positiveFlagId, isUp.Syntax, isUp)); 4992semanticModel: null, operation.InitialValue.Syntax, type: null, 5028IOperation condition = tryCallObjectForLoopControlHelper(operation.LimitValue.Syntax, 5124operation.LimitValue.Syntax, 5139condition = MakeInvalidOperation(operation.LimitValue.Syntax, booleanType, PopOperand(), limitReference); 5161operation.StepValue.Syntax, 5202operation.LimitValue.Syntax, 5222operation.LimitValue.Syntax, 5243var shiftConst = new LiteralOperation(semanticModel: null, operand.Syntax, _compilation.GetSpecialType(SpecialType.System_Int32), 5256operand.Syntax, 5271operand.Syntax, 5309controlVariableReferenceForAssignment.Syntax, 5344operation.StepValue.Syntax, 5360controlVariableReferenceForAssignment.Syntax, 5365controlVariableReferenceForAssignment.Syntax, 5395operation.StepValue.Syntax, 5412controlVariableReferenceForAssignment.Syntax, 5432declarator.Syntax, local.Type, constantValue: null, isImplicit: true); 5446return new FlowCaptureReferenceOperation(id, underlying.Syntax, underlying.Type, underlying.GetConstantValue()); 5589compareWith.Syntax, 5610patternClause.Pattern.Syntax, booleanType, isImplicit: true); 5833var initializationSemaphore = new StaticLocalInitializationSemaphoreOperation(localSymbol, declarator.Syntax, booleanType); 5847assignmentSyntax = declarator.Syntax; 5853assignmentSyntax = declaration.Syntax; 5858declaration.Syntax, 5876var localRef = new LocalReferenceOperation(localSymbol, isDeclaration: true, semanticModel: null, declarator.Syntax, localSymbol.Type, constantValue: null, isImplicit: true); 5933return new InvocationOperation(operation.TargetMethod, operation.ConstrainedToType, visitedInstance, operation.IsVirtual, visitedArguments, semanticModel: null, operation.Syntax, 5943return new FunctionPointerInvocationOperation(visitedPointer, visitedArguments, semanticModel: null, operation.Syntax, 5976IOperation initializedInstance = new NoPiaObjectCreationOperation(initializer: null, semanticModel: null, operation.Syntax, operation.Type, IsImplicit(operation)); 5988operation.Syntax, operation.Type, operation.GetConstantValue(), IsImplicit(operation)); 5996var initializedInstance = new TypeParameterObjectCreationOperation(initializer: null, semanticModel: null, operation.Syntax, operation.Type, IsImplicit(operation)); 6009hasDynamicArguments.ArgumentRefKinds, semanticModel: null, operation.Syntax, 6096result = new SimpleAssignmentOperation(assignmentOperation.IsRef, left, right, semanticModel: null, assignmentOperation.Syntax, 6234fieldReference.Syntax, fieldReference.Type, fieldReference.GetConstantValue(), IsImplicit(fieldReference)); 6238return new EventReferenceOperation(eventReference.Event, eventReference.ConstrainedToType, instance, semanticModel: null, eventReference.Syntax, 6244return new PropertyReferenceOperation(propertyReference.Property, propertyReference.ConstrainedToType, propertyArguments, instance, semanticModel: null, propertyReference.Syntax, 6250return new ArrayElementReferenceOperation(instance, indices, semanticModel: null, originalTarget.Syntax, originalTarget.Type, IsImplicit(originalTarget)); 6257semanticModel: null, originalTarget.Syntax, originalTarget.Type, IsImplicit(originalTarget)); 6269dynamicReference.ContainingType, semanticModel: null, dynamicReference.Syntax, 6360return MakeInvalidOperation(operation.Syntax, operation.Type, ImmutableArray<IOperation>.Empty); 6366return MakeInvalidOperation(operation.Syntax, operation.Type, ImmutableArray<IOperation>.Empty); 6374operation.Syntax, operation.Type, IsImplicit(operation)); 6399propertyReference.Instance.Syntax, propertyReference.Instance.Type, IsImplicit(propertyReference.Instance)); 6401semanticModel: null, propertyReference.Syntax, propertyReference.Type, IsImplicit(propertyReference)); 6404semanticModel: null, simpleAssignment.Syntax, simpleAssignment.Type, simpleAssignment.GetConstantValue(), IsImplicit(simpleAssignment)); 6418operation.Syntax, operation.Type, IsImplicit(operation)); 6492operation.Syntax, operation.Type, IsImplicit(operation)); 6538return new ArrayInitializerOperation(builder.ToImmutableAndFree(), semanticModel: null, initializer.Syntax, IsImplicit(initializer)); 6561spread.Syntax, 6570operation.Syntax, 6596return MakeInvalidOperation(operation.Syntax, operation.Type, ImmutableArray<IOperation>.Empty); 6601return new FlowCaptureReferenceOperation(_currentInterpolatedStringHandlerCreationContext.HandlerPlaceholder, operation.Syntax, operation.Type, operation.GetConstantValue()); 6604return new InstanceReferenceOperation(operation.ReferenceKind, semanticModel: null, operation.Syntax, operation.Type, IsImplicit(operation)); 6633dynamicMemberReference.ContainingType, semanticModel: null, dynamicMemberReference.Syntax, dynamicMemberReference.Type, IsImplicit(dynamicMemberReference)); 6642((HasDynamicArgumentsExpression)operation).ArgumentRefKinds, semanticModel: null, operation.Syntax, operation.Type, IsImplicit(operation)); 6653((HasDynamicArgumentsExpression)operation).ArgumentRefKinds, semanticModel: null, operation.Syntax, operation.Type, IsImplicit(operation)); 6659operation.ContainingType, semanticModel: null, operation.Syntax, operation.Type, IsImplicit(operation)); 6665return new DeconstructionAssignmentOperation(visitedTarget, visitedValue, semanticModel: null, operation.Syntax, operation.Type, IsImplicit(operation)); 6703return new TupleOperation(elementBuilder.ToImmutableAndFree(), tuple.NaturalType, semanticModel: null, tuple.Syntax, tuple.Type, IsImplicit(tuple)); 6713return new DeclarationExpressionOperation(VisitPreservingTupleOperations(operation.Expression), semanticModel: null, operation.Syntax, operation.Type, IsImplicit(operation)); 6761return new NoneOperation(ImmutableArray<IOperation>.Empty, semanticModel: null, operation.Syntax, operation.Type, operation.GetConstantValue(), IsImplicit(operation)); 6767new NoneOperation(VisitArray(((Operation)operation).ChildOperations.ToImmutableArray()), semanticModel: null, operation.Syntax, operation.Type, operation.GetConstantValue(), IsImplicit(operation))); 6843ConditionalBranch(new FlowCaptureReferenceOperation(outParameterFlowCapture, outParameterPlaceholder.Syntax, outParameterPlaceholder.Type, constantValue: null), jumpIfTrue: false, resultBlock); 6890return new FlowCaptureReferenceOperation(handlerCaptureId, operation.Syntax, operation.Type, operation.GetConstantValue()); 6971return new FlowCaptureReferenceOperation(_currentInterpolatedStringHandlerCreationContext.OutPlaceholder, operation.Syntax, operation.Type, operation.GetConstantValue(), isInitialization: true); 6983return new InvalidOperation(ImmutableArray<IOperation>.Empty, semanticModel: null, operation.Syntax, operation.Type, operation.GetConstantValue(), isImplicit: true); 6996return new InvalidOperation(ImmutableArray<IOperation>.Empty, semanticModel: null, operation.Syntax, operation.Type, operation.GetConstantValue(), isImplicit: true); 7066rewrittenElement = new InterpolationOperation(rewrittenExpression, rewrittenAlignment, rewrittenFormatString, semanticModel: null, element.Syntax, IsImplicit(element)); 7071rewrittenElement = new InterpolatedStringTextOperation(rewrittenInterpolationText, semanticModel: null, element.Syntax, IsImplicit(element)); 7083return new InterpolatedStringOperation(partsBuilder.ToImmutableAndFree(), semanticModel: null, operation.Syntax, operation.Type, operation.GetConstantValue(), IsImplicit(operation)); 7099return new LiteralOperation(semanticModel: null, operation.Syntax, operation.Type, operation.GetConstantValue(), IsImplicit(operation)); 7104return new LiteralOperation(semanticModel: null, operation.Syntax, operation.Type, operation.GetConstantValue(), IsImplicit(operation)); 7109return new Utf8StringOperation(operation.Value, semanticModel: null, operation.Syntax, operation.Type, IsImplicit(operation)); 7114return new LocalReferenceOperation(operation.Local, operation.IsDeclaration, semanticModel: null, operation.Syntax, 7120return new ParameterReferenceOperation(operation.Parameter, semanticModel: null, operation.Syntax, 7128operation.Syntax, operation.Type, operation.GetConstantValue(), IsImplicit(operation)); 7135operation.Syntax, operation.Type, IsImplicit(operation)); 7155return MakeInvalidOperation(operation.Syntax, operation.Type, ImmutableArray<IOperation>.Empty); 7164operation.Syntax, operation.Type, IsImplicit(operation)); 7171operation.Syntax, operation.Type, IsImplicit(operation)); 7176return new TypeOfOperation(operation.TypeOperand, semanticModel: null, operation.Syntax, operation.Type, IsImplicit(operation)); 7181return new ParenthesizedOperation(VisitRequired(operation.Operand), semanticModel: null, operation.Syntax, operation.Type, operation.GetConstantValue(), IsImplicit(operation)); 7186return new AwaitOperation(VisitRequired(operation.Operation), semanticModel: null, operation.Syntax, operation.Type, IsImplicit(operation)); 7191return new SizeOfOperation(operation.TypeOperand, semanticModel: null, operation.Syntax, operation.Type, operation.GetConstantValue(), IsImplicit(operation)); 7196return new StopOperation(semanticModel: null, operation.Syntax, IsImplicit(operation)); 7201return new IsTypeOperation(VisitRequired(operation.ValueOperand), operation.TypeOperand, operation.IsNegated, semanticModel: null, operation.Syntax, operation.Type, IsImplicit(operation)); 7209operation.Syntax, operation.Parameter.Type, isImplicit: true); 7223operation.Syntax, fieldSymbol.ContainingType, isImplicit: true); 7225operation.Syntax, fieldSymbol.Type, constantValue: null, isImplicit: true); 7241operation.Syntax, propertySymbol.ContainingType, isImplicit: true); 7251operation.Syntax, parameter.Type, constantValue: null, isImplicit: true); 7255semanticModel: null, operation.Syntax, isImplicit: true); 7267semanticModel: null, operation.Syntax, propertySymbol.Type, isImplicit: true); 7280initializer.Syntax, rewrittenTarget.Type, constantValue: null, isImplicit: true); 7308semanticModel: null, operation.EventReference.Syntax, operation.EventReference.Type, IsImplicit(operation.EventReference)); 7321operation.Syntax, operation.Type, IsImplicit(operation)); 7354semanticModel: null, operation.EventReference.Syntax, operation.EventReference.Type, IsImplicit(operation.EventReference)); 7358operation.Syntax, IsImplicit(operation))); 7363return new AddressOfOperation(VisitRequired(operation.Reference), semanticModel: null, operation.Syntax, operation.Type, IsImplicit(operation)); 7370operation.Kind, semanticModel: null, operation.Syntax, operation.Type, IsImplicit(operation)); 7375return new DiscardOperation(operation.DiscardSymbol, semanticModel: null, operation.Syntax, operation.Type, IsImplicit(operation)); 7380return new DiscardPatternOperation(pat.InputType, pat.NarrowedType, semanticModel: null, pat.Syntax, IsImplicit(pat)); 7385return new OmittedArgumentOperation(semanticModel: null, operation.Syntax, operation.Type, IsImplicit(operation)); 7419return new PlaceholderOperation(operation.PlaceholderKind, semanticModel: null, operation.Syntax, operation.Type, IsImplicit(operation)); 7424return new ConversionOperation(VisitRequired(operation.Operand), ((ConversionOperation)operation).ConversionConvertible, operation.IsTryCast, operation.IsChecked, semanticModel: null, operation.Syntax, operation.Type, operation.GetConstantValue(), IsImplicit(operation)); 7429return new DefaultValueOperation(semanticModel: null, operation.Syntax, operation.Type, operation.GetConstantValue(), IsImplicit(operation)); 7440operation.Syntax, operation.Type, IsImplicit(operation)); 7472IOperation initializedInstance = new InvalidOperation(children.ToImmutableAndFree(), semanticModel: null, operation.Syntax, operation.Type, 7496return new InvalidOperation(ImmutableArray<IOperation>.Empty, semanticModel: null, invalidOperation.Syntax, invalidOperation.Type, invalidOperation.GetConstantValue(), IsImplicit(invalidOperation)); 7503invalidOperation.Syntax, invalidOperation.Type, invalidOperation.GetConstantValue(), IsImplicit(operation))); 7522semanticModel: null, operation.Syntax, isImplicit); 7534return new ReDimClauseOperation(visitedOperand, visitedDimensionSizes, semanticModel: null, clause.Syntax, IsImplicit(clause)); 7545return new TranslatedQueryOperation(VisitRequired(operation.Operation), semanticModel: null, operation.Syntax, operation.Type, IsImplicit(operation)); 7551syntax: operation.Syntax, isImplicit: IsImplicit(operation)); 7562syntax: operation.Syntax, 7602syntax: operation.Syntax, 7614syntax: operation.Syntax, 7625syntax: operation.Syntax, 7638operation.Syntax, 7650operation.Syntax, 7664operation.Syntax, 7679operation.Syntax, 7689syntax: operation.Syntax, 7696operation.Syntax, operation.Type, IsImplicit(operation)); 7714return new RangeOperation(visitedLeftOperand, visitedRightOperand, operation.IsLifted, operation.Method, semanticModel: null, operation.Syntax, operation.Type, isImplicit: IsImplicit(operation)); 7760arm.Syntax, booleanType, IsImplicit(arm)); 7795? MakeInvalidOperation(operation.Syntax, type: _compilation.GetSpecialType(SpecialType.System_Object), ImmutableArray<IOperation>.Empty) 7797matchFailureCtor, initializer: null, ImmutableArray<IArgumentOperation>.Empty, semanticModel: null, operation.Syntax, 7833BlockOperation logicalBlock = BlockOperation.CreateTemporaryBlock(statementsBuilder.ToImmutableAndFree(), ((Operation)operation).OwningSemanticModel!, operation.Syntax); 7936semanticModel: null, operation.Syntax, operation.Type, isImplicit: true); 8012var valueCaptureRef = new FlowCaptureReferenceOperation(valueCaptureId, operation.Operand.Syntax, 8033var oldInstance = new FlowCaptureReferenceOperation(oldValueCaptureId, operation.Operand.Syntax, 8043var extraValueCaptureRef = new FlowCaptureReferenceOperation(extraValueCaptureId, operation.Operand.Syntax, 8097return new AttributeOperation(Visit(operation.Operation, captureIdForResult)!, semanticModel: null, operation.Syntax, IsImplicit(operation));
Operations\OperationCloner.cs (5)
21return new NoneOperation(VisitArray(((Operation)operation).ChildOperations.ToImmutableArray()), ((Operation)operation).OwningSemanticModel, operation.Syntax, operation.Type, operation.GetConstantValue(), operation.IsImplicit); 32return new DynamicObjectCreationOperation(Visit(operation.Initializer), VisitArray(operation.Arguments), ((HasDynamicArgumentsExpression)operation).ArgumentNames, ((HasDynamicArgumentsExpression)operation).ArgumentRefKinds, ((Operation)operation).OwningSemanticModel, operation.Syntax, operation.Type, operation.IsImplicit); 37return new DynamicInvocationOperation(Visit(operation.Operation), VisitArray(operation.Arguments), ((HasDynamicArgumentsExpression)operation).ArgumentNames, ((HasDynamicArgumentsExpression)operation).ArgumentRefKinds, ((Operation)operation).OwningSemanticModel, operation.Syntax, operation.Type, operation.IsImplicit); 42return new DynamicIndexerAccessOperation(Visit(operation.Operation), VisitArray(operation.Arguments), ((HasDynamicArgumentsExpression)operation).ArgumentNames, ((HasDynamicArgumentsExpression)operation).ArgumentRefKinds, ((Operation)operation).OwningSemanticModel, operation.Syntax, operation.Type, operation.IsImplicit); 47return new InvalidOperation(VisitArray(((InvalidOperation)operation).Children), ((Operation)operation).OwningSemanticModel, operation.Syntax, operation.Type, operation.GetConstantValue(), operation.IsImplicit);
Operations\OperationExtensions.cs (4)
41if (operation.Syntax == null) 51if (model is null || model.SyntaxTree != operation.Syntax.SyntaxTree) 53model = compilation.GetSemanticModel(operation.Syntax.SyntaxTree); 63return model.GetDiagnostics(operation.Syntax.Span, cancellationToken).Any(static d => d.DefaultSeverity == DiagnosticSeverity.Error);
Operations\OperationMapBuilder.cs (4)
113!argument.ContainsKey(operation.Syntax), 114$"Duplicate operation node for {operation.Syntax}. Existing node is {(argument.TryGetValue(operation.Syntax, out var original) ? (OperationKind?)original.Kind : null)}, new node is {operation.Kind}."); 115argument.Add(operation.Syntax, operation);
Operations\OperationNodes.cs (1)
156base(semanticModel: null, original.Syntax, isImplicit)
Microsoft.CodeAnalysis.CodeStyle (52)
src\Analyzers\Core\Analyzers\ConvertTypeofToNameof\AbstractConvertTypeOfToNameOfDiagnosticAnalyzer.cs (1)
41var node = context.Operation.Syntax;
src\Analyzers\Core\Analyzers\PopulateSwitch\AbstractPopulateSwitchDiagnosticAnalyzer.cs (1)
53if (switchOperation.Syntax is not TSwitchSyntax switchBlock || IsSwitchTypeUnknown(switchOperation))
src\Analyzers\Core\Analyzers\QualifyMemberAccess\AbstractQualifyMemberAccessDiagnosticAnalyzer.cs (2)
98if (!CanMemberAccessBeQualified(context.ContainingSymbol, instanceOperation.Syntax)) 106if (instanceOperation.Syntax is not TSimpleNameSyntax simpleName)
src\Analyzers\Core\Analyzers\RemoveRedundantEquality\AbstractRemoveRedundantEqualityDiagnosticAnalyzer.cs (2)
34var syntax = context.Operation.Syntax; 56var syntax = context.Operation.Syntax;
src\Analyzers\Core\Analyzers\RemoveUnusedMembers\AbstractRemoveUnusedMembersDiagnosticAnalyzer.cs (3)
297var methods = _analyzer.SemanticFacts.GetDeconstructionAssignmentMethods(operation.SemanticModel!, operation.Syntax); 416var symbols = _analyzer.SemanticFacts.GetForEachSymbols(operation.SemanticModel!, loopOperation.Syntax); 454var symbolInfo = nameofArgument.SemanticModel!.GetSymbolInfo(nameofArgument.Syntax, operationContext.CancellationToken);
src\Analyzers\Core\Analyzers\RemoveUnusedParametersAndValues\AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer.SymbolStartAnalyzer.BlockAnalyzer.cs (7)
99if (!symbolStartAnalyzer._compilationAnalyzer.TryGetOptions(firstBlock.Syntax.SyntaxTree, 116firstBlock.Syntax.SyntaxTree != filterTree) 126var root = firstBlock.Syntax.SyntaxTree.GetRoot(context.CancellationToken); 127var spanStart = firstBlock.Syntax.SpanStart; 140if (operationBlock.Syntax.GetDiagnostics().ToImmutableArrayOrEmpty().HasAnyErrors()) 151if (operationBlock.Syntax.DescendantNodes(descendIntoTrivia: true) 216value.Syntax.GetLocation(),
src\Analyzers\Core\Analyzers\SimplifyInterpolation\AbstractSimplifyInterpolationDiagnosticAnalyzer.cs (1)
71additionalLocations: [interpolation.Syntax.GetLocation()],
src\Analyzers\Core\Analyzers\SimplifyInterpolation\AbstractSimplifyInterpolationHelpers.cs (7)
50.SelectAsArray(interpolation.Syntax.SyntaxTree.GetLocation); 83!syntaxFacts.IsBaseExpression(instance.Syntax) && 97unnecessarySpans.AddRange(invocation.Syntax.Span 99.Subtract(GetSpanWithinLiteralQuotes(virtualCharService, literal.Syntax.GetFirstToken()))); 112unnecessarySpans.AddRange(invocation.Syntax.Span 214var alignmentSyntax = alignmentOp.Syntax; 220unnecessarySpans.AddRange(invocation.Syntax.Span
src\Analyzers\Core\Analyzers\SimplifyLinqExpression\AbstractSimplifyLinqExpressionDiagnosticAnalyzer.cs (4)
124if (context.Operation.Syntax.GetDiagnostics().Any(diagnostic => diagnostic.Severity == DiagnosticSeverity.Error)) 174context.ReportDiagnostic(Diagnostic.Create(Descriptor, nextInvocation.Syntax.GetLocation())); 188if (invocation.Syntax is not TInvocationExpressionSyntax invocationNode || 200if (invocation.Syntax is not TInvocationExpressionSyntax invocationNode ||
src\Analyzers\Core\Analyzers\UseConditionalExpression\AbstractUseConditionalExpressionDiagnosticAnalyzer.cs (1)
44if (ifOperation.Syntax is not TIfStatementSyntax ifStatement)
src\Analyzers\Core\Analyzers\UseConditionalExpression\ForAssignment\UseConditionalExpressionForAssignmentHelpers.cs (2)
50!syntaxFacts.AreEquivalent(trueAssignment.Target.Syntax, falseAssignment.Target.Syntax))
src\Analyzers\Core\Analyzers\UseConditionalExpression\UseConditionalExpressionHelpers.cs (5)
37if (syntaxFacts.SpansPreprocessorDirective(ifOperation.Syntax, whenFalse.Syntax)) 45if (HasRegularComments(syntaxFacts, whenTrue.Syntax) || 46HasRegularComments(syntaxFacts, whenFalse.Syntax)) 93if (!syntaxFacts.SupportsThrowExpression(anyThrow.Syntax.SyntaxTree.Options))
src\Analyzers\Core\Analyzers\UseExplicitTupleName\UseExplicitTupleNameDiagnosticAnalyzer.cs (1)
57var memberAccessSyntax = fieldReferenceOperation.Syntax;
src\Analyzers\Core\Analyzers\UseSystemHashCode\UseSystemHashCodeDiagnosticAnalyzer.cs (2)
72var option = context.Options.GetAnalyzerOptions(operation.Syntax.SyntaxTree).PreferSystemHashCode; 77var operationLocation = operation.Syntax.GetLocation();
src\Analyzers\Core\Analyzers\UseThrowExpression\AbstractUseThrowExpressionDiagnosticAnalyzer.cs (9)
78var throwStatementSyntax = throwOperation.Syntax; 130ifOperation.Syntax.GetLocation(), 131throwOperation.Exception.Syntax.GetLocation(), 132assignmentExpression.Value.Syntax.GetLocation(), 133expressionStatement.Syntax.GetLocation()); 150statements[ifOperationIndex + 1].Syntax, 151statements[expressionStatementIndex - 1].Syntax); 162var exprDataFlow = semanticModel.AnalyzeDataFlow(assignmentExpression.Target.Syntax); 273var throwStatement = throwOperation.Syntax;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Extensions\AnalysisContextExtensions.cs (3)
187=> operationBlock.Syntax.FindNode(context.FilterSpan, findInTrivia, getInnermostNodeForTie); 193=> operationBlock.Syntax.FindNode(context.FilterSpan, findInTrivia, getInnermostNodeForTie); 199=> context.Operation.Syntax.FindNode(context.FilterSpan, findInTrivia, getInnermostNodeForTie);
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\FlowAnalysis\SymbolUsageAnalysis\SymbolUsageAnalysis.DataFlowAnalyzer.FlowGraphAnalysisData.cs (1)
194var dataFlow = operation.SemanticModel.AnalyzeDataFlow(operation.Syntax);
Microsoft.CodeAnalysis.CodeStyle.Fixes (19)
src\Analyzers\Core\CodeFixes\SimplifyInterpolation\AbstractSimplifyInterpolationCodeFixProvider.cs (1)
62if (interpolation?.Syntax is TInterpolationSyntax interpolationSyntax &&
src\Analyzers\Core\CodeFixes\UseConditionalExpression\AbstractUseConditionalExpressionCodeFixProvider.cs (4)
115trueValue.Syntax, falseValue.Syntax, formattingOptions, cancellationToken).ConfigureAwait(false); 126=> operation.Condition.Syntax; 164var sourceSyntax = value.Syntax;
src\Analyzers\Core\CodeFixes\UseConditionalExpression\ForAssignment\AbstractUseConditionalExpressionForAssignmentCodeFixProvider.cs (6)
108var ifStatement = (TIfStatementSyntax)ifOperation.Syntax; 111assignment.Target.Syntax, 115ifOperation.Syntax, 133var localDeclaration = localDeclarationOperation.Syntax; 147editor.RemoveNode(ifOperation.Syntax, GetRemoveOptions(syntaxFacts, ifOperation.Syntax));
src\Analyzers\Core\CodeFixes\UseConditionalExpression\ForReturn\AbstractUseConditionalExpressionForReturnCodeFixProvider.cs (2)
91editor.RemoveNode(falseStatement.Syntax, GetRemoveOptions(syntaxFacts, falseStatement.Syntax));
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\LanguageServices\InitializeParameter\AbstractInitializerParameterService.cs (2)
176return statement.Syntax; 181return statementIndex > 0 && blockStatement.Operations[statementIndex - 1] is { IsImplicit: false, Syntax: var priorSyntax }
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\Utilities\NullableHelpers.cs (4)
76assignmentOperation.Syntax.RawKind == semanticFacts.SyntaxFacts.SyntaxKinds.SimpleAssignmentExpression) 83var typeInfo = semanticModel.GetTypeInfo(assignmentOperation.Value.Syntax, cancellationToken); 99var foreachInfo = semanticFacts.GetForEachSymbols(semanticModel, forEachLoop.Syntax); 111var syntax = variableDeclarator.GetVariableInitializer()!.Value.Syntax;
Microsoft.CodeAnalysis.CSharp (6)
Operations\CSharpOperationFactory.cs (3)
1050Debug.Assert(isImplicit || target.Syntax != syntax || target.IsImplicit || boundConversion.ConversionGroupOpt != null); 1052isImplicit = isImplicit || (target.Syntax == syntax && !target.IsImplicit); 2369Debug.Assert(valueOperation.Syntax != part.Syntax);
Operations\CSharpOperationFactory_Methods.cs (3)
40(SyntaxNode syntax, bool isImplicit) = expression.Syntax is { Parent: ArgumentSyntax or AttributeArgumentSyntax } ? (expression.Syntax.Parent, expression.WasCompilerGenerated) : (value.Syntax, true); 446syntax: value.Syntax, 464var assignmentSyntax = value.Syntax?.Parent ?? syntax;
Microsoft.CodeAnalysis.CSharp.CodeStyle (56)
src\Analyzers\CSharp\Analyzers\ConvertTypeofToNameof\CSharpConvertTypeOfToNameOfDiagnosticAnalyzer.cs (1)
26var node = context.Operation.Syntax;
src\Analyzers\CSharp\Analyzers\MakeStructMemberReadOnly\CSharpMakeStructMemberReadOnlyAnalyzer.cs (4)
272CSharpSemanticFacts.Instance.IsWrittenTo(semanticModel, instanceOperation.Syntax, cancellationToken)) 294if (CSharpSemanticFacts.Instance.IsWrittenTo(semanticModel, fieldReference.Syntax, cancellationToken)) 305if (CSharpSemanticFacts.Instance.IsWrittenTo(semanticModel, propertyReference.Syntax, cancellationToken)) 336if (CSharpSemanticFacts.Instance.IsWrittenTo(semanticModel, operation.Syntax, cancellationToken))
src\Analyzers\CSharp\Analyzers\QualifyMemberAccess\CSharpQualifyMemberAccessDiagnosticAnalyzer.cs (1)
67protected override Location GetLocation(IOperation operation) => operation.Syntax.GetLocation();
src\Analyzers\CSharp\Analyzers\RemoveUnusedParametersAndValues\CSharpRemoveUnusedParametersAndValuesDiagnosticAnalyzer.cs (6)
69var statementAncestor = unusedSymbolWriteOperation.Syntax.FirstAncestorOrSelf<StatementSyntax>()?.Parent; 79!blockOperation.Syntax.IsKind(SyntaxKind.Block); 83switch (unusedDefinition.Syntax) 103if (unusedDefinition.Syntax.Parent is ForEachStatementSyntax forEachStatement && 104forEachStatement.Type == unusedDefinition.Syntax) 109return unusedDefinition.Syntax.GetLocation();
src\Analyzers\CSharp\Analyzers\SimplifyInterpolation\CSharpSimplifyInterpolationHelpers.cs (1)
20return operation.Syntax switch
src\Analyzers\CSharp\Analyzers\UseConditionalExpression\CSharpUseConditionalExpressionForReturnDiagnosticAnalyzer.cs (1)
39if (block.Syntax.Parent is UnsafeStatementSyntax or CheckedStatementSyntax)
src\Analyzers\CSharp\Analyzers\UseIndexOrRangeOperator\CSharpUseIndexOperatorDiagnosticAnalyzer.cs (2)
176if (subtraction.Syntax is not BinaryExpressionSyntax binaryExpression) 201if (CSharpSemanticFacts.Instance.IsInExpressionTree(semanticModel, instance.Syntax, infoCache.ExpressionOfTType, cancellationToken))
src\Analyzers\CSharp\Analyzers\UseIndexOrRangeOperator\CSharpUseRangeOperatorDiagnosticAnalyzer.cs (9)
86if (CSharpSemanticFacts.Instance.IsInExpressionTree(semanticModel, operation.Syntax, infoCache.ExpressionOfTType, context.CancellationToken)) 96if (invocation.Syntax is not InvocationExpressionSyntax invocationSyntax || 192if (!CSharpSyntaxFacts.Instance.AreEquivalent(lengthOperation.Syntax, subtraction.RightOperand.Syntax)) 208if (!CSharpSyntaxFacts.Instance.AreEquivalent(startOperation.Syntax, subtraction.RightOperand.Syntax)) 246if (CSharpSyntaxFacts.Instance.AreEquivalent(startOperation.Syntax, subtraction.RightOperand.Syntax)) 308return !invocation.Syntax.IsLeftSideOfAnyAssignExpression() || indexer == null || !IsWriteableIndexer(invocation, indexer);
src\Analyzers\CSharp\Analyzers\UseIndexOrRangeOperator\Helpers.cs (2)
48CSharpSyntaxFacts.Instance.AreEquivalent(instance.Syntax, propertyRef.Instance.Syntax);
src\Analyzers\CSharp\Analyzers\UseIsNullCheck\CSharpUseNullCheckOverTypeCheckDiagnosticAnalyzer.cs (3)
61context.Operation.Syntax is not UnaryPatternSyntax) 81Descriptor, context.Operation.Syntax.GetLocation(), notificationOption, context.Options, additionalLocations: null, properties: null)); 89var syntax = operation.Syntax;
src\Analyzers\CSharp\Analyzers\UsePatternCombinators\CSharpUsePatternCombinatorsAnalyzer.cs (9)
19return pattern?.Target.Syntax is ExpressionSyntax ? pattern : null; 50case IBinaryOperation { OperatorKind: ConditionalOr, Syntax: BinaryExpressionSyntax syntax } op: 53case IBinaryOperation { OperatorKind: ConditionalAnd, Syntax: BinaryExpressionSyntax syntax } op: 62case IIsTypeOperation { Syntax: BinaryExpressionSyntax binaryExpression } op: 65case IIsPatternOperation { Pattern.Syntax: PatternSyntax pattern } op: 102ConstantResult.Left when op.LeftOperand.Syntax is ExpressionSyntax left 107ConstantResult.Right when op.RightOperand.Syntax is ExpressionSyntax right 117ConstantResult.Left when op.LeftOperand.Syntax is ExpressionSyntax left 119ConstantResult.Right when op.RightOperand.Syntax is ExpressionSyntax right
src\Analyzers\CSharp\Analyzers\UsePrimaryConstructor\CSharpUsePrimaryConstructorDiagnosticAnalyzer.cs (2)
512operation is IParameterReferenceOperation { Syntax: IdentifierNameSyntax parameterName } parameterReference) 574var symbols = semanticModel.LookupSymbols(operation.Syntax.SpanStart, name: parameter.Name);
src\Analyzers\CSharp\Analyzers\UseSystemThreadingLock\CSharpUseSystemThreadingLockDiagnosticAnalyzer.cs (1)
187if (lockOperation.Syntax.ContainsYield())
src\Analyzers\CSharp\Analyzers\UseUtf8StringLiteral\UseUtf8StringLiteralDiagnosticAnalyzer.cs (10)
82if (arrayCreationOperation.Syntax.Ancestors().OfType<AttributeSyntax>().Any()) 88if (arrayCreationOperation.Syntax.IsInExpressionTree(semanticModel, expressionType, context.CancellationToken)) 101if (arrayCreationOperation.Syntax is ImplicitArrayCreationExpressionSyntax or ArrayCreationExpressionSyntax) 103ReportArrayCreationDiagnostic(context, arrayCreationOperation.Syntax, option.Notification); 105else if (elements is [{ Syntax.Parent: ArgumentSyntax }, ..]) 108ReportParameterArrayDiagnostic(context, arrayCreationOperation.Syntax, elements, option.Notification, ArrayCreationOperationLocation.Descendants); 110else if (elements is [{ Syntax.Parent: (kind: SyntaxKind.CollectionInitializerExpression) }, ..]) 114ReportParameterArrayDiagnostic(context, arrayCreationOperation.Syntax, elements, option.Notification, ArrayCreationOperationLocation.Ancestors); 124var span = TextSpan.FromBounds(elements[0].Syntax.SpanStart, elements[^1].Syntax.Span.End);
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Simplification\Simplifiers\CastSimplifier.cs (3)
278conversionOperation.Syntax == castNode && 943if (IsExplicitCast(conversionOperation.Syntax)) 1463var argumentSyntax = argument?.Syntax as ArgumentSyntax;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Utilities\TypeStyle\CSharpUseImplicitTypeHelper.cs (1)
239var argumentOp = invocationOp.Arguments.FirstOrDefault(a => a.Syntax == argument);
Microsoft.CodeAnalysis.CSharp.CodeStyle.Fixes (12)
src\Analyzers\CSharp\CodeFixes\ConvertToRecord\ConvertToRecordHelpers.cs (3)
295? assignment.Syntax as ExpressionSyntax 305if (arg is { Parameter: IParameterSymbol param, Value.Syntax: ExpressionSyntax captured }) 385Value: IOperation { Syntax: ExpressionSyntax syntax }
src\Analyzers\CSharp\CodeFixes\MakeLocalFunctionStatic\MakeLocalFunctionStaticCodeFixHelper.cs (2)
158syntaxEditor.ReplaceNode(instanceReference.Syntax, IdentifierName("@this")); 160else if (instanceReference.Syntax is SimpleNameSyntax name)
src\Analyzers\CSharp\CodeFixes\UseConditionalExpression\CSharpUseConditionalExpressionForAssignmentCodeFixProvider.cs (1)
38=> (VariableDeclaratorSyntax)declarator.Syntax;
src\Analyzers\CSharp\CodeFixes\UseConditionalExpression\CSharpUseConditionalExpressionForReturnCodeFixProvider.cs (2)
46if (operation.Syntax is IfStatementSyntax { Condition: CheckedExpressionSyntax exp }) 54if (returnOperation.Syntax is ReturnStatementSyntax { Expression: CheckedExpressionSyntax exp })
src\Analyzers\CSharp\CodeFixes\UseConditionalExpression\CSharpUseConditionalExpressionHelpers.cs (1)
15var throwStatement = (ThrowStatementSyntax)throwOperation.Syntax;
src\Analyzers\CSharp\CodeFixes\UseUtf8StringLiteral\UseUtf8StringLiteralCodeFixProvider.cs (1)
120.Where(a => a.Initializer?.ElementValues.FirstOrDefault()?.Syntax.SpanStart == diagnostic.Location.SourceSpan.Start)
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\LanguageServices\InitializeParameter\InitializeParameterHelpers.cs (2)
159=> blockStatement?.Syntax is BlockSyntax block 161: blockStatement?.Syntax;
Microsoft.CodeAnalysis.CSharp.Emit3.UnitTests (78)
Diagnostics\DiagnosticAnalyzerTests.cs (3)
2348ReportDiagnosticsCore(addDiagnostic, operation.Syntax.Location, $"Operation: {name}"); 3863context => context.ReportDiagnostic(CodeAnalysis.Diagnostic.Create(Rule, context.Operation.Syntax.GetLocation())), 3869context => context.ReportDiagnostic(CodeAnalysis.Diagnostic.Create(Rule, context.Operation.Syntax.GetLocation())),
Diagnostics\GetDiagnosticsTests.cs (6)
983context => analyzeNode(context.Operation.Syntax, context.ContainingSymbol, context.ReportDiagnostic), 990blockEndContext.ReportDiagnostic(CodeAnalysis.Diagnostic.Create(DescriptorForBlockEnd, operationBlock.Syntax.GetLocation())); 992if (operationBlock.Syntax is PropertyDeclarationSyntax or IndexerDeclarationSyntax) 993throw new Exception($"Unexpected topmost node for operation block '{operationBlock.Syntax.Kind()}'"); 1646AssertEx.SetEqual(expectedOperationCallbacks, analyzer.AnalyzedOperations.Select(op => op.Syntax.ToString()).ToHashSet()); 1650AssertEx.SetEqual(expectedOperationInsideBlockCallbacks, analyzer.AnalyzedOperationsInsideOperationBlock.Select(op => op.Syntax.ToString()).ToHashSet());
Semantics\PrimaryConstructorTests.cs (37)
1157VerifyFlowGraph(comp, operation.Parent.Parent.Syntax, @" 4328Assert.Equal(SyntaxKind.ClassDeclaration, context.Operation.Syntax.Kind()); 4332Assert.Equal(SyntaxKind.ClassDeclaration, context.Operation.Syntax.Kind()); 4336Assert.Equal(SyntaxKind.ConstructorDeclaration, context.Operation.Syntax.Kind()); 4350Assert.Equal(SyntaxKind.PrimaryConstructorBaseType, context.Operation.Syntax.Kind()); 4365Assert.Equal(SyntaxKind.BaseConstructorInitializer, context.Operation.Syntax.Kind()); 4386switch (context.Operation.Syntax.ToString()) 4432switch (context.Operation.Syntax.ToString()) 4516Assert.Equal("= 0", context.OperationBlocks[0].Syntax.ToString()); 4519Assert.Equal("Attr1(100)", context.OperationBlocks[1].Syntax.ToString()); 4527Assert.Equal("= 1", context.OperationBlocks[0].Syntax.ToString()); 4530Assert.Equal("Attr2(200)", context.OperationBlocks[1].Syntax.ToString()); 4533Assert.Equal("A(2)", context.OperationBlocks[2].Syntax.ToString()); 4541Assert.Equal("= 4", context.OperationBlocks[0].Syntax.ToString()); 4544Assert.Equal("Attr3(300)", context.OperationBlocks[1].Syntax.ToString()); 4549Assert.Equal(": base(5)", context.OperationBlocks[3].Syntax.ToString()); 4650Assert.Equal("= 0", context.OperationBlocks[0].Syntax.ToString()); 4653Assert.Equal("Attr1(100)", context.OperationBlocks[1].Syntax.ToString()); 4663Assert.Equal("= 1", context.OperationBlocks[0].Syntax.ToString()); 4666Assert.Equal("Attr2(200)", context.OperationBlocks[1].Syntax.ToString()); 4669Assert.Equal("A(2)", context.OperationBlocks[2].Syntax.ToString()); 4679Assert.Equal("= 4", context.OperationBlocks[0].Syntax.ToString()); 4682Assert.Equal("Attr3(300)", context.OperationBlocks[1].Syntax.ToString()); 4687Assert.Equal(": base(5)", context.OperationBlocks[3].Syntax.ToString()); 4724Assert.Equal("= 0", context.OperationBlocks[0].Syntax.ToString()); 4727Assert.Equal("Attr1(100)", context.OperationBlocks[1].Syntax.ToString()); 4735Assert.Equal("= 1", context.OperationBlocks[0].Syntax.ToString()); 4738Assert.Equal("Attr2(200)", context.OperationBlocks[1].Syntax.ToString()); 4741Assert.Equal("A(2)", context.OperationBlocks[2].Syntax.ToString()); 4749Assert.Equal("= 4", context.OperationBlocks[0].Syntax.ToString()); 4752Assert.Equal("Attr3(300)", context.OperationBlocks[1].Syntax.ToString()); 4757Assert.Equal(": base(5)", context.OperationBlocks[3].Syntax.ToString()); 5696Assert.Equal(SyntaxKind.RecordDeclaration, context.Operation.Syntax.Kind()); 5713switch (context.Operation.Syntax.ToString()) 5731switch (context.Operation.Syntax.ToString()) 5791Assert.Equal("= 0", context.OperationBlocks[0].Syntax.ToString()); 5794Assert.Equal("Attr1(100)", context.OperationBlocks[1].Syntax.ToString());
Semantics\RecordTests.cs (32)
21275VerifyFlowGraph(comp, operation.Parent.Parent.Syntax, @" 26836Assert.Equal(SyntaxKind.RecordDeclaration, context.Operation.Syntax.Kind()); 26840Assert.Equal(SyntaxKind.RecordDeclaration, context.Operation.Syntax.Kind()); 26844Assert.Equal(SyntaxKind.ConstructorDeclaration, context.Operation.Syntax.Kind()); 26858Assert.Equal(SyntaxKind.PrimaryConstructorBaseType, context.Operation.Syntax.Kind()); 26873Assert.Equal(SyntaxKind.BaseConstructorInitializer, context.Operation.Syntax.Kind()); 26894switch (context.Operation.Syntax.ToString()) 26940switch (context.Operation.Syntax.ToString()) 27024Assert.Equal("= 0", context.OperationBlocks[0].Syntax.ToString()); 27027Assert.Equal("Attr1(100)", context.OperationBlocks[1].Syntax.ToString()); 27035Assert.Equal("= 1", context.OperationBlocks[0].Syntax.ToString()); 27038Assert.Equal("Attr2(200)", context.OperationBlocks[1].Syntax.ToString()); 27041Assert.Equal("A(2)", context.OperationBlocks[2].Syntax.ToString()); 27049Assert.Equal("= 4", context.OperationBlocks[0].Syntax.ToString()); 27052Assert.Equal("Attr3(300)", context.OperationBlocks[1].Syntax.ToString()); 27057Assert.Equal(": base(5)", context.OperationBlocks[3].Syntax.ToString()); 27158Assert.Equal("= 0", context.OperationBlocks[0].Syntax.ToString()); 27161Assert.Equal("Attr1(100)", context.OperationBlocks[1].Syntax.ToString()); 27171Assert.Equal("= 1", context.OperationBlocks[0].Syntax.ToString()); 27174Assert.Equal("Attr2(200)", context.OperationBlocks[1].Syntax.ToString()); 27177Assert.Equal("A(2)", context.OperationBlocks[2].Syntax.ToString()); 27187Assert.Equal("= 4", context.OperationBlocks[0].Syntax.ToString()); 27190Assert.Equal("Attr3(300)", context.OperationBlocks[1].Syntax.ToString()); 27195Assert.Equal(": base(5)", context.OperationBlocks[3].Syntax.ToString()); 27232Assert.Equal("= 0", context.OperationBlocks[0].Syntax.ToString()); 27235Assert.Equal("Attr1(100)", context.OperationBlocks[1].Syntax.ToString()); 27243Assert.Equal("= 1", context.OperationBlocks[0].Syntax.ToString()); 27246Assert.Equal("Attr2(200)", context.OperationBlocks[1].Syntax.ToString()); 27249Assert.Equal("A(2)", context.OperationBlocks[2].Syntax.ToString()); 27257Assert.Equal("= 4", context.OperationBlocks[0].Syntax.ToString()); 27260Assert.Equal("Attr3(300)", context.OperationBlocks[1].Syntax.ToString()); 27265Assert.Equal(": base(5)", context.OperationBlocks[3].Syntax.ToString());
Microsoft.CodeAnalysis.CSharp.Features (76)
ConvertIfToSwitch\CSharpConvertIfToSwitchCodeRefactoringProvider.Analyzer.cs (2)
19=> !operation.SemanticModel.AnalyzeControlFlow(operation.Syntax).EndPointIsReachable; 32=> !operation.SemanticModel.AnalyzeControlFlow(operation.Syntax).ExitPoints.Any(static n => n.IsKind(SyntaxKind.BreakStatement));
ConvertIfToSwitch\CSharpConvertIfToSwitchCodeRefactoringProvider.Rewriting.cs (3)
63IReturnOperation { ReturnedValue: { } value } => (ExpressionSyntax)value.Syntax, 64IThrowOperation { Exception: { } exception } => ThrowExpression((ExpressionSyntax)exception.Syntax), 110var node = operation.Syntax;
ExtractMethod\CSharpMethodExtractor.CSharpCodeGenerator.cs (4)
797if (!ReturnOperationBelongsToMethod(returnOperation.Syntax, methodOperation.Syntax)) 800var syntax = returnOperation.ReturnedValue?.Syntax ?? returnOperation.Syntax;
ImplementInterface\CSharpImplementExplicitlyCodeRefactoringProvider.cs (1)
137instance.Syntax, (current, g) =>
src\Analyzers\CSharp\Analyzers\ConvertTypeofToNameof\CSharpConvertTypeOfToNameOfDiagnosticAnalyzer.cs (1)
26var node = context.Operation.Syntax;
src\Analyzers\CSharp\Analyzers\MakeStructMemberReadOnly\CSharpMakeStructMemberReadOnlyAnalyzer.cs (4)
272CSharpSemanticFacts.Instance.IsWrittenTo(semanticModel, instanceOperation.Syntax, cancellationToken)) 294if (CSharpSemanticFacts.Instance.IsWrittenTo(semanticModel, fieldReference.Syntax, cancellationToken)) 305if (CSharpSemanticFacts.Instance.IsWrittenTo(semanticModel, propertyReference.Syntax, cancellationToken)) 336if (CSharpSemanticFacts.Instance.IsWrittenTo(semanticModel, operation.Syntax, cancellationToken))
src\Analyzers\CSharp\Analyzers\QualifyMemberAccess\CSharpQualifyMemberAccessDiagnosticAnalyzer.cs (1)
67protected override Location GetLocation(IOperation operation) => operation.Syntax.GetLocation();
src\Analyzers\CSharp\Analyzers\RemoveUnusedParametersAndValues\CSharpRemoveUnusedParametersAndValuesDiagnosticAnalyzer.cs (6)
69var statementAncestor = unusedSymbolWriteOperation.Syntax.FirstAncestorOrSelf<StatementSyntax>()?.Parent; 79!blockOperation.Syntax.IsKind(SyntaxKind.Block); 83switch (unusedDefinition.Syntax) 103if (unusedDefinition.Syntax.Parent is ForEachStatementSyntax forEachStatement && 104forEachStatement.Type == unusedDefinition.Syntax) 109return unusedDefinition.Syntax.GetLocation();
src\Analyzers\CSharp\Analyzers\SimplifyInterpolation\CSharpSimplifyInterpolationHelpers.cs (1)
20return operation.Syntax switch
src\Analyzers\CSharp\Analyzers\UseConditionalExpression\CSharpUseConditionalExpressionForReturnDiagnosticAnalyzer.cs (1)
39if (block.Syntax.Parent is UnsafeStatementSyntax or CheckedStatementSyntax)
src\Analyzers\CSharp\Analyzers\UseIndexOrRangeOperator\CSharpUseIndexOperatorDiagnosticAnalyzer.cs (2)
176if (subtraction.Syntax is not BinaryExpressionSyntax binaryExpression) 201if (CSharpSemanticFacts.Instance.IsInExpressionTree(semanticModel, instance.Syntax, infoCache.ExpressionOfTType, cancellationToken))
src\Analyzers\CSharp\Analyzers\UseIndexOrRangeOperator\CSharpUseRangeOperatorDiagnosticAnalyzer.cs (9)
86if (CSharpSemanticFacts.Instance.IsInExpressionTree(semanticModel, operation.Syntax, infoCache.ExpressionOfTType, context.CancellationToken)) 96if (invocation.Syntax is not InvocationExpressionSyntax invocationSyntax || 192if (!CSharpSyntaxFacts.Instance.AreEquivalent(lengthOperation.Syntax, subtraction.RightOperand.Syntax)) 208if (!CSharpSyntaxFacts.Instance.AreEquivalent(startOperation.Syntax, subtraction.RightOperand.Syntax)) 246if (CSharpSyntaxFacts.Instance.AreEquivalent(startOperation.Syntax, subtraction.RightOperand.Syntax)) 308return !invocation.Syntax.IsLeftSideOfAnyAssignExpression() || indexer == null || !IsWriteableIndexer(invocation, indexer);
src\Analyzers\CSharp\Analyzers\UseIndexOrRangeOperator\Helpers.cs (2)
48CSharpSyntaxFacts.Instance.AreEquivalent(instance.Syntax, propertyRef.Instance.Syntax);
src\Analyzers\CSharp\Analyzers\UseIsNullCheck\CSharpUseNullCheckOverTypeCheckDiagnosticAnalyzer.cs (3)
61context.Operation.Syntax is not UnaryPatternSyntax) 81Descriptor, context.Operation.Syntax.GetLocation(), notificationOption, context.Options, additionalLocations: null, properties: null)); 89var syntax = operation.Syntax;
src\Analyzers\CSharp\Analyzers\UsePatternCombinators\CSharpUsePatternCombinatorsAnalyzer.cs (9)
19return pattern?.Target.Syntax is ExpressionSyntax ? pattern : null; 50case IBinaryOperation { OperatorKind: ConditionalOr, Syntax: BinaryExpressionSyntax syntax } op: 53case IBinaryOperation { OperatorKind: ConditionalAnd, Syntax: BinaryExpressionSyntax syntax } op: 62case IIsTypeOperation { Syntax: BinaryExpressionSyntax binaryExpression } op: 65case IIsPatternOperation { Pattern.Syntax: PatternSyntax pattern } op: 102ConstantResult.Left when op.LeftOperand.Syntax is ExpressionSyntax left 107ConstantResult.Right when op.RightOperand.Syntax is ExpressionSyntax right 117ConstantResult.Left when op.LeftOperand.Syntax is ExpressionSyntax left 119ConstantResult.Right when op.RightOperand.Syntax is ExpressionSyntax right
src\Analyzers\CSharp\Analyzers\UsePrimaryConstructor\CSharpUsePrimaryConstructorDiagnosticAnalyzer.cs (2)
512operation is IParameterReferenceOperation { Syntax: IdentifierNameSyntax parameterName } parameterReference) 574var symbols = semanticModel.LookupSymbols(operation.Syntax.SpanStart, name: parameter.Name);
src\Analyzers\CSharp\Analyzers\UseSystemThreadingLock\CSharpUseSystemThreadingLockDiagnosticAnalyzer.cs (1)
187if (lockOperation.Syntax.ContainsYield())
src\Analyzers\CSharp\Analyzers\UseUtf8StringLiteral\UseUtf8StringLiteralDiagnosticAnalyzer.cs (10)
82if (arrayCreationOperation.Syntax.Ancestors().OfType<AttributeSyntax>().Any()) 88if (arrayCreationOperation.Syntax.IsInExpressionTree(semanticModel, expressionType, context.CancellationToken)) 101if (arrayCreationOperation.Syntax is ImplicitArrayCreationExpressionSyntax or ArrayCreationExpressionSyntax) 103ReportArrayCreationDiagnostic(context, arrayCreationOperation.Syntax, option.Notification); 105else if (elements is [{ Syntax.Parent: ArgumentSyntax }, ..]) 108ReportParameterArrayDiagnostic(context, arrayCreationOperation.Syntax, elements, option.Notification, ArrayCreationOperationLocation.Descendants); 110else if (elements is [{ Syntax.Parent: (kind: SyntaxKind.CollectionInitializerExpression) }, ..]) 114ReportParameterArrayDiagnostic(context, arrayCreationOperation.Syntax, elements, option.Notification, ArrayCreationOperationLocation.Ancestors); 124var span = TextSpan.FromBounds(elements[0].Syntax.SpanStart, elements[^1].Syntax.Span.End);
src\Analyzers\CSharp\CodeFixes\ConvertToRecord\ConvertToRecordHelpers.cs (3)
295? assignment.Syntax as ExpressionSyntax 305if (arg is { Parameter: IParameterSymbol param, Value.Syntax: ExpressionSyntax captured }) 385Value: IOperation { Syntax: ExpressionSyntax syntax }
src\Analyzers\CSharp\CodeFixes\MakeLocalFunctionStatic\MakeLocalFunctionStaticCodeFixHelper.cs (2)
158syntaxEditor.ReplaceNode(instanceReference.Syntax, IdentifierName("@this")); 160else if (instanceReference.Syntax is SimpleNameSyntax name)
src\Analyzers\CSharp\CodeFixes\UseConditionalExpression\CSharpUseConditionalExpressionForAssignmentCodeFixProvider.cs (1)
38=> (VariableDeclaratorSyntax)declarator.Syntax;
src\Analyzers\CSharp\CodeFixes\UseConditionalExpression\CSharpUseConditionalExpressionForReturnCodeFixProvider.cs (2)
46if (operation.Syntax is IfStatementSyntax { Condition: CheckedExpressionSyntax exp }) 54if (returnOperation.Syntax is ReturnStatementSyntax { Expression: CheckedExpressionSyntax exp })
src\Analyzers\CSharp\CodeFixes\UseConditionalExpression\CSharpUseConditionalExpressionHelpers.cs (1)
15var throwStatement = (ThrowStatementSyntax)throwOperation.Syntax;
src\Analyzers\CSharp\CodeFixes\UseIndexOrRangeOperator\CSharpUseRangeOperatorCodeFixProvider.cs (2)
160return (startExpr: null, startFromEnd: false, (ExpressionSyntax)subtraction.RightOperand.Syntax, endFromEnd: true); 174return ((ExpressionSyntax)subtraction.RightOperand.Syntax, startFromEnd: true, endExpr: null, endFromEnd: false);
src\Analyzers\CSharp\CodeFixes\UsePatternCombinators\CSharpUsePatternCombinatorsCodeFixProvider.cs (2)
86editor.ReplaceNode(expression, IsPatternExpression((ExpressionSyntax)pattern.Target.Syntax, patternSyntax)); 127var governingType = semanticModel.GetTypeInfo(p.Target.Syntax).Type.RemoveNullableIfPresent();
src\Analyzers\CSharp\CodeFixes\UseUtf8StringLiteral\UseUtf8StringLiteralCodeFixProvider.cs (1)
120.Where(a => a.Initializer?.ElementValues.FirstOrDefault()?.Syntax.SpanStart == diagnostic.Location.SourceSpan.Start)
Microsoft.CodeAnalysis.CSharp.IOperation.UnitTests (5)
IOperation\IOperationTests.cs (1)
690Assert.Same(expectedRootSyntax, operation.Syntax);
IOperation\IOperationTests_IBranchOperation.Extensions.cs (4)
363Assert.Equal(expected.Syntax, actual.Syntax); 370Assert.Equal(expected.Syntax, actual.Syntax);
Microsoft.CodeAnalysis.CSharp.Semantic.UnitTests (20)
Semantics\RecordStructTests.cs (5)
6422Assert.Equal(SyntaxKind.RecordDeclaration, context.Operation.Syntax.Kind()); 6439switch (context.Operation.Syntax.ToString()) 6457switch (context.Operation.Syntax.ToString()) 6517Assert.Equal("= 0", context.OperationBlocks[0].Syntax.ToString()); 6520Assert.Equal("Attr1(100)", context.OperationBlocks[1].Syntax.ToString());
Semantics\TopLevelStatementsTests.cs (15)
6721Assert.Same(context.ContainingSymbol.DeclaringSyntaxReferences.Single().SyntaxTree, context.Operation.Syntax.SyntaxTree); 6723Assert.Equal(SyntaxKind.InvocationExpression, context.Operation.Syntax.Kind()); 6725switch (context.Operation.Syntax.ToString()) 6742Assert.Same(context.ContainingSymbol.DeclaringSyntaxReferences.Single().GetSyntax(), context.Operation.Syntax); 6743Assert.Equal(SyntaxKind.CompilationUnit, context.Operation.Syntax.Kind()); 6745switch (context.Operation.Syntax.ToString()) 6801Assert.Equal(SyntaxKind.CompilationUnit, context.OperationBlocks.Single().Syntax.Kind()); 6803switch (context.OperationBlocks.Single().Syntax.ToString()) 6859Assert.Equal(SyntaxKind.CompilationUnit, context.OperationBlocks.Single().Syntax.Kind()); 6861switch (context.OperationBlocks.Single().Syntax.ToString()) 7353Assert.Equal(SyntaxKind.CompilationUnit, context.OperationBlocks.Single().Syntax.Kind()); 7355switch (context.OperationBlocks.Single().Syntax.ToString()) 7420Assert.Same(context.ContainingSymbol.DeclaringSyntaxReferences.Single().GetSyntax(), context.Operation.Syntax); 7421Assert.Equal(SyntaxKind.CompilationUnit, context.Operation.Syntax.Kind()); 7423switch (context.Operation.Syntax.ToString())
Microsoft.CodeAnalysis.CSharp.Workspaces (6)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Simplification\Simplifiers\CastSimplifier.cs (3)
278conversionOperation.Syntax == castNode && 943if (IsExplicitCast(conversionOperation.Syntax)) 1463var argumentSyntax = argument?.Syntax as ArgumentSyntax;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Utilities\TypeStyle\CSharpUseImplicitTypeHelper.cs (1)
239var argumentOp = invocationOp.Arguments.FirstOrDefault(a => a.Syntax == argument);
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\LanguageServices\InitializeParameter\InitializeParameterHelpers.cs (2)
159=> blockStatement?.Syntax is BlockSyntax block 161: blockStatement?.Syntax;
Microsoft.CodeAnalysis.EditorFeatures.UnitTests (2)
CodeFixes\CodeFixServiceTests.cs (2)
1190=> variableDeclarations.Add(context.Operation.Syntax), OperationKind.VariableDeclaration); 1210context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Operation.Syntax.GetLocation())),
Microsoft.CodeAnalysis.Features (91)
ConvertIfToSwitch\AbstractConvertIfToSwitchCodeRefactoringProvider.Analyzer.cs (17)
81sections.Add(new AnalyzedSwitchSection(labels: default, defaultBodyOpt, defaultBodyOpt.Syntax)); 196return new AnalyzedSwitchSection(labels.ToImmutable(), operation.WhenTrue, operation.Syntax); 287ConstantResult.Left when op.LeftOperand.Syntax is TExpressionSyntax left 289ConstantResult.Right when op.RightOperand.Syntax is TExpressionSyntax right 322if (Supports(Feature.CaseGuard) && op.RightOperand.Syntax is TExpressionSyntax node) 332when Supports(Feature.IsTypePattern) && CheckTargetExpression(op.ValueOperand) && op.Syntax is TIsExpressionSyntax node: 336when Supports(Feature.SourcePattern) && CheckTargetExpression(op.Value) && op.Pattern.Syntax is TPatternSyntax pattern: 350ConstantResult.Left when op.LeftOperand.Syntax is TExpressionSyntax left 352ConstantResult.Right when op.RightOperand.Syntax is TExpressionSyntax right 385when CheckTargetExpression(low.Expression, high.Expression) => (low.Value.Syntax, high.Value.Syntax), 387when CheckTargetExpression(low.Expression, high.Expression) => (low.Value.Syntax, high.Value.Syntax), 392=> _syntaxFacts.AreEquivalent(left.Syntax, right.Syntax) && this.CheckTargetExpression(left); 453var expression = operation.Syntax; 473return CanImplicitlyConvert(operation.SemanticModel, operation.Syntax, _switchTargetType);
InitializeParameter\AbstractAddParameterCheckCodeRefactoringProvider.cs (5)
194var syntax = statement.Syntax; 201syntaxFacts.IsThrowExpression(coalesceExpression.WhenNull.Syntax)) 274if (!CanOffer(blockStatementOpt.Syntax)) 426return checkStatement.Syntax; 438return statementIndex > 0 && blockStatement.Operations[statementIndex - 1] is { IsImplicit: false, Syntax: var priorSyntax }
InitializeParameter\AbstractInitializeMemberFromParameterCodeRefactoringProviderMemberCreation.cs (2)
374nodesToTrack.Add(blockStatement.Syntax); 396currentBlockStatement = (IBlockOperation?)currentSemanticModel.GetOperation(currentRoot.GetCurrentNode(blockStatement.Syntax)!, cancellationToken);
InitializeParameter\AbstractInitializeParameterCodeRefactoringProvider.cs (1)
185foreach (var child in condition.Syntax.DescendantNodes().OfType<TExpressionSyntax>())
InlineMethod\AbstractInlineMethodRefactoringProvider.MethodParametersInfo.cs (3)
380.Where(argument => argument.Value.Syntax is TExpressionSyntax 381&& !_syntaxFacts.IsDeclarationExpression(argument.Value.Syntax)) 526return (TExpressionSyntax)syntaxGenerator.AddParentheses(argumentExpressionOperation.Syntax);
src\Analyzers\Core\Analyzers\ConvertTypeofToNameof\AbstractConvertTypeOfToNameOfDiagnosticAnalyzer.cs (1)
41var node = context.Operation.Syntax;
src\Analyzers\Core\Analyzers\PopulateSwitch\AbstractPopulateSwitchDiagnosticAnalyzer.cs (1)
53if (switchOperation.Syntax is not TSwitchSyntax switchBlock || IsSwitchTypeUnknown(switchOperation))
src\Analyzers\Core\Analyzers\QualifyMemberAccess\AbstractQualifyMemberAccessDiagnosticAnalyzer.cs (2)
98if (!CanMemberAccessBeQualified(context.ContainingSymbol, instanceOperation.Syntax)) 106if (instanceOperation.Syntax is not TSimpleNameSyntax simpleName)
src\Analyzers\Core\Analyzers\RemoveRedundantEquality\AbstractRemoveRedundantEqualityDiagnosticAnalyzer.cs (2)
34var syntax = context.Operation.Syntax; 56var syntax = context.Operation.Syntax;
src\Analyzers\Core\Analyzers\RemoveUnusedMembers\AbstractRemoveUnusedMembersDiagnosticAnalyzer.cs (3)
297var methods = _analyzer.SemanticFacts.GetDeconstructionAssignmentMethods(operation.SemanticModel!, operation.Syntax); 416var symbols = _analyzer.SemanticFacts.GetForEachSymbols(operation.SemanticModel!, loopOperation.Syntax); 454var symbolInfo = nameofArgument.SemanticModel!.GetSymbolInfo(nameofArgument.Syntax, operationContext.CancellationToken);
src\Analyzers\Core\Analyzers\RemoveUnusedParametersAndValues\AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer.SymbolStartAnalyzer.BlockAnalyzer.cs (7)
99if (!symbolStartAnalyzer._compilationAnalyzer.TryGetOptions(firstBlock.Syntax.SyntaxTree, 116firstBlock.Syntax.SyntaxTree != filterTree) 126var root = firstBlock.Syntax.SyntaxTree.GetRoot(context.CancellationToken); 127var spanStart = firstBlock.Syntax.SpanStart; 140if (operationBlock.Syntax.GetDiagnostics().ToImmutableArrayOrEmpty().HasAnyErrors()) 151if (operationBlock.Syntax.DescendantNodes(descendIntoTrivia: true) 216value.Syntax.GetLocation(),
src\Analyzers\Core\Analyzers\SimplifyInterpolation\AbstractSimplifyInterpolationDiagnosticAnalyzer.cs (1)
71additionalLocations: [interpolation.Syntax.GetLocation()],
src\Analyzers\Core\Analyzers\SimplifyInterpolation\AbstractSimplifyInterpolationHelpers.cs (7)
50.SelectAsArray(interpolation.Syntax.SyntaxTree.GetLocation); 83!syntaxFacts.IsBaseExpression(instance.Syntax) && 97unnecessarySpans.AddRange(invocation.Syntax.Span 99.Subtract(GetSpanWithinLiteralQuotes(virtualCharService, literal.Syntax.GetFirstToken()))); 112unnecessarySpans.AddRange(invocation.Syntax.Span 214var alignmentSyntax = alignmentOp.Syntax; 220unnecessarySpans.AddRange(invocation.Syntax.Span
src\Analyzers\Core\Analyzers\SimplifyLinqExpression\AbstractSimplifyLinqExpressionDiagnosticAnalyzer.cs (4)
124if (context.Operation.Syntax.GetDiagnostics().Any(diagnostic => diagnostic.Severity == DiagnosticSeverity.Error)) 174context.ReportDiagnostic(Diagnostic.Create(Descriptor, nextInvocation.Syntax.GetLocation())); 188if (invocation.Syntax is not TInvocationExpressionSyntax invocationNode || 200if (invocation.Syntax is not TInvocationExpressionSyntax invocationNode ||
src\Analyzers\Core\Analyzers\UseConditionalExpression\AbstractUseConditionalExpressionDiagnosticAnalyzer.cs (1)
44if (ifOperation.Syntax is not TIfStatementSyntax ifStatement)
src\Analyzers\Core\Analyzers\UseConditionalExpression\ForAssignment\UseConditionalExpressionForAssignmentHelpers.cs (2)
50!syntaxFacts.AreEquivalent(trueAssignment.Target.Syntax, falseAssignment.Target.Syntax))
src\Analyzers\Core\Analyzers\UseConditionalExpression\UseConditionalExpressionHelpers.cs (5)
37if (syntaxFacts.SpansPreprocessorDirective(ifOperation.Syntax, whenFalse.Syntax)) 45if (HasRegularComments(syntaxFacts, whenTrue.Syntax) || 46HasRegularComments(syntaxFacts, whenFalse.Syntax)) 93if (!syntaxFacts.SupportsThrowExpression(anyThrow.Syntax.SyntaxTree.Options))
src\Analyzers\Core\Analyzers\UseExplicitTupleName\UseExplicitTupleNameDiagnosticAnalyzer.cs (1)
57var memberAccessSyntax = fieldReferenceOperation.Syntax;
src\Analyzers\Core\Analyzers\UseSystemHashCode\UseSystemHashCodeDiagnosticAnalyzer.cs (2)
72var option = context.Options.GetAnalyzerOptions(operation.Syntax.SyntaxTree).PreferSystemHashCode; 77var operationLocation = operation.Syntax.GetLocation();
src\Analyzers\Core\Analyzers\UseThrowExpression\AbstractUseThrowExpressionDiagnosticAnalyzer.cs (9)
78var throwStatementSyntax = throwOperation.Syntax; 130ifOperation.Syntax.GetLocation(), 131throwOperation.Exception.Syntax.GetLocation(), 132assignmentExpression.Value.Syntax.GetLocation(), 133expressionStatement.Syntax.GetLocation()); 150statements[ifOperationIndex + 1].Syntax, 151statements[expressionStatementIndex - 1].Syntax); 162var exprDataFlow = semanticModel.AnalyzeDataFlow(assignmentExpression.Target.Syntax); 273var throwStatement = throwOperation.Syntax;
src\Analyzers\Core\CodeFixes\SimplifyInterpolation\AbstractSimplifyInterpolationCodeFixProvider.cs (1)
62if (interpolation?.Syntax is TInterpolationSyntax interpolationSyntax &&
src\Analyzers\Core\CodeFixes\UseConditionalExpression\AbstractUseConditionalExpressionCodeFixProvider.cs (4)
115trueValue.Syntax, falseValue.Syntax, formattingOptions, cancellationToken).ConfigureAwait(false); 126=> operation.Condition.Syntax; 164var sourceSyntax = value.Syntax;
src\Analyzers\Core\CodeFixes\UseConditionalExpression\ForAssignment\AbstractUseConditionalExpressionForAssignmentCodeFixProvider.cs (6)
108var ifStatement = (TIfStatementSyntax)ifOperation.Syntax; 111assignment.Target.Syntax, 115ifOperation.Syntax, 133var localDeclaration = localDeclarationOperation.Syntax; 147editor.RemoveNode(ifOperation.Syntax, GetRemoveOptions(syntaxFacts, ifOperation.Syntax));
src\Analyzers\Core\CodeFixes\UseConditionalExpression\ForReturn\AbstractUseConditionalExpressionForReturnCodeFixProvider.cs (2)
91editor.RemoveNode(falseStatement.Syntax, GetRemoveOptions(syntaxFacts, falseStatement.Syntax));
ValueTracking\ValueTracker.OperationCollector.cs (2)
79var symbolInfo = semanticModel.GetSymbolInfo(operation.Syntax, cancellationToken); 176operation.Syntax.GetLocation(),
Microsoft.CodeAnalysis.Test.Utilities (154)
CommonTestBase.cs (2)
686VerifyOperationTreeSpine(semanticModel, set, child.Syntax); 690Assert.True(semanticModel.Root.FullSpan.Contains(child.Syntax.FullSpan));
Compilation\CompilationExtensions.cs (7)
300Assert.True(node == operation.Syntax, $"Expected : {node} - Actual : {operation.Syntax}"); 312roots.Add((operation, semanticModel.GetDeclaredSymbol(operation.Syntax))); 333explicitNodeMap.Add(operation.Syntax, operation); 337Assert.False(true, $"Duplicate explicit node for syntax ({operation.Syntax.RawKind}): {operation.Syntax.ToString()}"); 367if (blockOperation.Syntax.SyntaxTree.Options.Kind != SourceCodeKind.Script)
Compilation\ControlFlowGraphVerifier.cs (36)
78var declaredSymbol = model.GetDeclaredSymbol(operationRoot.Syntax); 349var model = compilation.GetSemanticModel(graph.OriginalOperation.Syntax.SyntaxTree); 350if (model.GetDiagnostics(graph.OriginalOperation.Syntax.Span). 525referencesAfter.All(r => isLongLivedCaptureReferenceSyntax(r.Syntax)), 545VisualBasicSyntaxNode syntax = applyParenthesizedIfAnyVB((VisualBasicSyntaxNode)candidate.Syntax); 572VisualBasicSyntaxNode syntax = applyParenthesizedIfAnyVB((VisualBasicSyntaxNode)candidate.Syntax); 597return reference.Syntax is CSharp.Syntax.SwitchExpressionSyntax switchExpr && switchExpr.Arms.Count == 0; 610CSharpSyntaxNode syntax = applyParenthesizedOrNullSuppressionIfAnyCS((CSharpSyntaxNode)candidate.Syntax); 626VisualBasicSyntaxNode syntax = applyParenthesizedIfAnyVB((VisualBasicSyntaxNode)candidate.Syntax); 653CSharpSyntaxNode syntax = applyParenthesizedOrNullSuppressionIfAnyCS((CSharpSyntaxNode)candidate.Syntax); 664VisualBasicSyntaxNode syntax = applyParenthesizedIfAnyVB((VisualBasicSyntaxNode)candidate.Syntax); 692VisualBasicSyntaxNode syntax = applyParenthesizedIfAnyVB((VisualBasicSyntaxNode)candidate.Syntax); 696if (query.Syntax is VisualBasic.Syntax.QueryExpressionSyntax querySyntax && 698aggregate.AggregateKeyword.SpanStart < candidate.Syntax.SpanStart && 699aggregate.IntoKeyword.SpanStart > candidate.Syntax.SpanStart && 829SyntaxNode captureReferenceSyntax = reference.Syntax; 867CSharpSyntaxNode referenceSyntax = applyParenthesizedOrNullSuppressionIfAnyCS((CSharpSyntaxNode)reference.Syntax); 880CSharpSyntaxNode referenceSyntax = applyParenthesizedOrNullSuppressionIfAnyCS((CSharpSyntaxNode)reference.Syntax); 911Syntax: CSharpSyntaxNode syntax 954if (binOp.Syntax is CSharp.Syntax.BinaryExpressionSyntax binOpSyntax && 956binOpSyntax.Left == applyParenthesizedOrNullSuppressionIfAnyCS((CSharpSyntaxNode)reference.Syntax) && 957binOpSyntax.Right == applyParenthesizedOrNullSuppressionIfAnyCS((CSharpSyntaxNode)binOp.RightOperand.Syntax)) 964var referenceSyntax = applyParenthesizedIfAnyVB((VisualBasicSyntaxNode)reference.Syntax); 965if (binOp.Syntax is VisualBasic.Syntax.BinaryExpressionSyntax binOpSyntax && 968binOpSyntax.Right == applyParenthesizedIfAnyVB((VisualBasicSyntaxNode)binOp.RightOperand.Syntax)) 972else if (binOp.Syntax is VisualBasic.Syntax.RangeCaseClauseSyntax range && 975range.UpperBound == applyParenthesizedIfAnyVB((VisualBasicSyntaxNode)binOp.RightOperand.Syntax)) 979else if (binOp.Syntax is VisualBasic.Syntax.CaseStatementSyntax caseStmt && 983caseStmt.Cases.Contains(applyParenthesizedIfAnyVB((VisualBasicSyntaxNode)binOp.RightOperand.Syntax) as CaseClauseSyntax)) 1000assignment.Syntax.Parent is VisualBasic.Syntax.ForStatementSyntax forStmt && 1001assignment.Syntax == forStmt.ControlVariable && 1002reference.Syntax == assignment.Syntax && 1003assignment.Value.Syntax == forStmt.StepClause.StepValue) 1013if (isLongLivedCaptureReferenceSyntax(reference.Syntax)) 1080if (whenNotNull.Contains(candidate.Syntax))
Compilation\OperationTreeVerifier.cs (6)
131Assert.NotNull(operation.Syntax); 132LogString($" (Syntax: {GetSnippetFromSyntax(operation.Syntax)})"); 313_explicitNodeMap.Add(operation.Syntax, operation); 317Assert.False(true, $"Duplicate explicit node for syntax ({operation.Syntax.RawKind}): {operation.Syntax.ToString()}"); 334Assert.True(operation.Syntax.Language == operation.Language);
Compilation\TestOperationVisitor.cs (18)
46var syntax = operation.Syntax; 200explicitNodeMap.Add(descendant.Syntax, descendant); 204Assert.False(true, $"Duplicate explicit node for syntax ({descendant.Syntax.RawKind}): {descendant.Syntax.ToString()}"); 558Assert.False(operation.Instance.IsImplicit, $"Implicit {nameof(IInstanceReferenceOperation)} on {operation.Syntax}"); 588Assert.True(operation.Descendants().All(n => n.IsImplicit), $"Explicit node in default argument value ({operation.Syntax.RawKind}): {operation.Syntax.ToString()}"); 668Assert.False(operation.Instance.IsImplicit, $"Implicit {nameof(IInstanceReferenceOperation)} on {operation.Syntax}"); 757CheckOperators(operation.SemanticModel, operation.Syntax); 792CheckOperators(operation.SemanticModel, operation.Syntax); 1176if (operation.Syntax.Language == LanguageNames.CSharp) 1415if (operation.Syntax.IsKind(CSharp.SyntaxKind.VarPattern) || 1417operation.Syntax.IsKind(CSharp.SyntaxKind.SingleVariableDesignation)) 1429(operation.Syntax as CSharp.Syntax.DeclarationPatternSyntax)?.Designation ?? 1430(operation.Syntax as CSharp.Syntax.VarPatternSyntax)?.Designation ?? 1431(operation.Syntax as CSharp.Syntax.VariableDesignationSyntax); 1463var designation = (operation.Syntax as CSharp.Syntax.ListPatternSyntax)?.Designation; 1500var designation = (operation.Syntax as CSharp.Syntax.RecursivePatternSyntax)?.Designation;
Diagnostics\BoxingOperationAnalyzer.cs (2)
53Report(operationContext, conversion.Syntax); 66Report(operationContext, invocation.Instance.Syntax);
Diagnostics\CommonDiagnosticAnalyzers.cs (15)
1258return _controlFlowGraphMapOpt.Values.OrderBy(flowGraphAndSymbol => flowGraphAndSymbol.Graph.OriginalOperation.Syntax.SpanStart).ToImmutableArray(); 1353ReportDiagnostic(operationContext.ReportDiagnostic, operationContext.Operation.Syntax.GetLocation()); 1365ReportDiagnostic(operationContext.ReportDiagnostic, operationContext.Operation.Syntax.GetLocation()); 1445var diagnostic = Diagnostic.Create(Descriptor, operation.Syntax.GetLocation(), operation.Field.Name, operation.Field.ConstantValue); 1466var diagnostic = Diagnostic.Create(Descriptor, operationContext.Operation.Syntax.GetLocation(), operationContext.ContainingSymbol.Name); 2074operationContext.ReportDiagnostic(Diagnostic.Create(OperationRule, Location.None, symbolStartContext.Symbol.Name, operationContext.ContainingSymbol.Name, operationContext.Operation.Syntax.ToString(), _analyzerId)); 2149diagnostics.Add(Diagnostic.Create(OperationOrderingRule, Location.None, symbolStartContext.Symbol, operationContext.Operation.Syntax.ToString(), _analyzerId)); 2758ReportDiagnostics($"RegisterOperationAction({operationContext.Operation.Syntax}) in RegisterSymbolStartAction", operationContext.Operation.Syntax.SyntaxTree, operationContext.ContainingSymbol, operationContext.ReportDiagnostic), 2772ReportDiagnostics($"RegisterOperationAction({operationContext.Operation.Syntax})", operationContext.Operation.Syntax.SyntaxTree, operationContext.ContainingSymbol, operationContext.ReportDiagnostic), 2785ReportDiagnostics($"RegisterOperationAction({operationContext.Operation.Syntax}) in RegisterOperationBlockStartAction", operationContext.Operation.Syntax.SyntaxTree, operationContext.ContainingSymbol, operationContext.ReportDiagnostic), 2888context => context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Operation.Syntax.GetLocation())), 2943context.RegisterOperationAction(context => HandleCallback(context.Operation.Syntax.GetLocation(), context.Compilation, context.ReportDiagnostic, context.CancellationToken), OperationKind.VariableDeclaration);
Diagnostics\CouldHaveMoreSpecificTypeAnalyzer.cs (1)
66SyntaxNode syntax = increment.Syntax;
Diagnostics\EmptyArrayAnalyzer.cs (1)
83Report(operationContext, arrayCreation.Syntax);
Diagnostics\OperationTestAnalyzer.cs (66)
59operationContext.ReportDiagnostic(Diagnostic.Create(InvalidStatementDescriptor, operationContext.Operation.Syntax.GetLocation())); 63operationContext.ReportDiagnostic(Diagnostic.Create(InvalidExpressionDescriptor, operationContext.Operation.Syntax.GetLocation())); 73operationContext.ReportDiagnostic(Diagnostic.Create(IsInvalidDescriptor, operationContext.Operation.Syntax.GetLocation())); 109operationContext.ReportDiagnostic(Diagnostic.Create(ExpressionDescriptor, operationContext.Operation.Syntax.GetLocation())); 213Report(operationContext, forLoop.Syntax, BigForDescriptor); 453Report(operationContext, switchOperation.Value.Syntax, SparseSwitchDescriptor); 457Report(operationContext, switchOperation.Value.Syntax, NoDefaultSwitchDescriptor); 461Report(operationContext, switchOperation.Value.Syntax, OnlyDefaultSwitchDescriptor); 549operationContext.ReportDiagnostic(Diagnostic.Create(InvalidArgumentDescriptor, argument.Syntax.GetLocation())); 555operationContext.ReportDiagnostic(Diagnostic.Create(UseDefaultArgumentDescriptor, invocation.Syntax.GetLocation(), argument.Parameter.Name)); 569Report(operationContext, invocation.Syntax, BigParamArrayArgumentsDescriptor); 592Report(operationContext, argument.Syntax, OutOfNumericalOrderArgumentsDescriptor); 635operationContext.ReportDiagnostic(Diagnostic.Create(SeventeenDescriptor, literal.Syntax.GetLocation())); 670Report(operationContext, argument.Syntax, NullArgumentsDescriptor); 716Report(operationContext, initializer.Syntax, initializer.Kind == OperationKind.FieldReference ? DoNotUseFieldInitializerDescriptor : DoNotUsePropertyInitializerDescriptor); 757Report(operationContext, assignment.Syntax, DoNotUseMemberAssignmentDescriptor); 797Report(operationContext, initializer.Syntax, DoNotUseLargeListOfArrayInitializersDescriptor); 845Report(operationContext, declarationStatement.Syntax, TooManyLocalVarDeclarationsDescriptor); 905Report(operationContext, caseClause.Syntax, HasDefaultCaseDescriptor); 912Report(operationContext, switchSection.Syntax, MultipleCaseClausesDescriptor); 955instanceReference.Syntax.GetLocation())); 1034operationContext.ReportDiagnostic(Diagnostic.Create(EventReferenceDescriptor, operationContext.Operation.Syntax.GetLocation())); 1042operationContext.ReportDiagnostic(Diagnostic.Create(eventAssignment.Adds ? HandlerAddedDescriptor : HandlerRemovedDescriptor, operationContext.Operation.Syntax.GetLocation())); 1046operationContext.ReportDiagnostic(Diagnostic.Create(InvalidEventDescriptor, eventAssignment.Syntax.GetLocation())); 1054operationContext.ReportDiagnostic(Diagnostic.Create(PropertyReferenceDescriptor, operationContext.Operation.Syntax.GetLocation())); 1061operationContext.ReportDiagnostic(Diagnostic.Create(FieldReferenceDescriptor, operationContext.Operation.Syntax.GetLocation())); 1068operationContext.ReportDiagnostic(Diagnostic.Create(MethodBindingDescriptor, operationContext.Operation.Syntax.GetLocation())); 1111operationContext.ReportDiagnostic(Diagnostic.Create(LongParamsDescriptor, argument.Value.Syntax.GetLocation())); 1126operationContext.ReportDiagnostic(Diagnostic.Create(InvalidConstructorDescriptor, creation.Syntax.GetLocation())); 1138operationContext.ReportDiagnostic(Diagnostic.Create(LongParamsDescriptor, argument.Value.Syntax.GetLocation())); 1184operationContext.ReportDiagnostic(Diagnostic.Create(EqualsValueDescriptor, equalsValue.Syntax.GetLocation())); 1195operationContext.ReportDiagnostic(Diagnostic.Create(EqualsValueDescriptor, equalsValue.Syntax.GetLocation())); 1226operationContext.ReportDiagnostic(Diagnostic.Create(NoneOperationDescriptor, operationContext.Operation.Syntax.GetLocation())); 1262operationContext.ReportDiagnostic(Diagnostic.Create(AddressOfDescriptor, addressOfOperation.Syntax.GetLocation())); 1266operationContext.ReportDiagnostic(Diagnostic.Create(InvalidAddressOfReferenceDescriptor, addressOfOperation.Reference.Syntax.GetLocation())); 1314operationContext.ReportDiagnostic(Diagnostic.Create(LambdaExpressionDescriptor, operationContext.Operation.Syntax.GetLocation())); 1323operationContext.ReportDiagnostic(Diagnostic.Create(TooManyStatementsInLambdaExpressionDescriptor, operationContext.Operation.Syntax.GetLocation())); 1336operationContext.ReportDiagnostic(Diagnostic.Create(NoneOperationInLambdaExpressionDescriptor, operationContext.Operation.Syntax.GetLocation())); 1408operationContext.ReportDiagnostic(Diagnostic.Create(StaticMemberDescriptor, operation.Syntax.GetLocation())); 1412operationContext.ReportDiagnostic(Diagnostic.Create(StaticMemberWithInstanceDescriptor, operation.Syntax.GetLocation())); 1452operationContext.ReportDiagnostic(Diagnostic.Create(LabelDescriptor, operationContext.Operation.Syntax.GetLocation())); 1466operationContext.ReportDiagnostic(Diagnostic.Create(GotoDescriptor, branch.Syntax.GetLocation())); 1518operationContext.ReportDiagnostic(Diagnostic.Create(OperatorAddMethodDescriptor, binary.Syntax.GetLocation())); 1523operationContext.ReportDiagnostic(Diagnostic.Create(DoubleMultiplyDescriptor, binary.Syntax.GetLocation())); 1534operationContext.ReportDiagnostic(Diagnostic.Create(OperatorMinusMethodDescriptor, unary.Syntax.GetLocation())); 1539operationContext.ReportDiagnostic(Diagnostic.Create(BooleanNotDescriptor, unary.Syntax.GetLocation())); 1544operationContext.ReportDiagnostic(Diagnostic.Create(BooleanNotDescriptor, unary.Syntax.GetLocation())); 1574binary.Syntax.GetLocation(), 1627binary.Syntax.GetLocation(), 1651unary.Syntax.GetLocation(), 1707paramsarrayArgumentOperation.Syntax.GetLocation())); 1731if (operation.Syntax == null) 1791operationContext.ReportDiagnostic(Diagnostic.Create(InvalidBinaryDescriptor, binary.Syntax.GetLocation())); 1799operationContext.ReportDiagnostic(Diagnostic.Create(InvalidUnaryDescriptor, unary.Syntax.GetLocation())); 1807operationContext.ReportDiagnostic(Diagnostic.Create(InvalidIncrementDescriptor, inc.Syntax.GetLocation())); 1848operationContext.ReportDiagnostic(Diagnostic.Create(ConditionalAccessOperationDescriptor, conditionalAccess.Syntax.GetLocation())); 1857operationContext.ReportDiagnostic(Diagnostic.Create(ConditionalAccessInstanceOperationDescriptor, conditionalAccessInstance.Syntax.GetLocation())); 1897operationContext.ReportDiagnostic(Diagnostic.Create(InvalidConversionExpressionDescriptor, conversion.Syntax.GetLocation())); 1935operationContext.ReportDiagnostic(Diagnostic.Create(ForLoopConditionCrashDescriptor, forLoop.LimitValue.Syntax.GetLocation())); 1974operationContext.ReportDiagnostic(Diagnostic.Create(UnaryTrueDescriptor, unary.Syntax.GetLocation())); 1978operationContext.ReportDiagnostic(Diagnostic.Create(UnaryFalseDescriptor, unary.Syntax.GetLocation())); 2015operationContext.ReportDiagnostic(Diagnostic.Create(AssignmentOperationDescriptor, operationContext.Operation.Syntax.GetLocation())); 2052operationContext.ReportDiagnostic(Diagnostic.Create(LiteralDescriptor, literal.Syntax.GetLocation(), literal.Syntax.ToString())); 2080Diagnostic.Create(OperationActionDescriptor, operationContext.Operation.Syntax.GetLocation(), "Operation", "Analysis")); 2111Diagnostic.Create(OperationActionDescriptor, operationContext.Operation.Syntax.GetLocation(), "Operation", "CompilationStart within Analysis"));
Microsoft.CodeAnalysis.VisualBasic (3)
Operations\VisualBasicOperationFactory_Methods.vb (3)
260syntax = value.Syntax 336value.Syntax, 348Dim syntax As SyntaxNode = If(value.Syntax?.Parent, expression.Syntax)
Microsoft.CodeAnalysis.VisualBasic.CodeStyle (6)
src\Analyzers\VisualBasic\Analyzers\ConvertTypeofToNameof\VisualBasicConvertTypeOfToNameOfDiagnosticAnalyzer.vb (1)
22Dim node = context.Operation.Syntax
src\Analyzers\VisualBasic\Analyzers\QualifyMemberAccess\VisualBasicQualifyMemberAccessDiagnosticAnalyzer.vb (2)
41Dim unaryExpressionSyntax As UnaryExpressionSyntax = TryCast(operation.Syntax, UnaryExpressionSyntax) 46Return operation.Syntax.GetLocation()
src\Analyzers\VisualBasic\Analyzers\RemoveUnusedParametersAndValues\VisualBasicRemoveUnusedParametersAndValuesDiagnosticAnalyzer.vb (2)
50Return TryCast(expressionStatement.Syntax, CallStatementSyntax) IsNot Nothing 75Return unusedDefinition.Syntax.GetLocation()
src\Analyzers\VisualBasic\Analyzers\SimplifyInterpolation\VisualBasicSimplifyInterpolationHelpers.vb (1)
19Return operation.Syntax
Microsoft.CodeAnalysis.VisualBasic.CodeStyle.Fixes (2)
src\Analyzers\VisualBasic\CodeFixes\UseConditionalExpression\VisualBasicUseConditionalExpressionForAssignmentCodeFixProvider.vb (1)
47Return DirectCast(declarator.Syntax.Parent, VariableDeclaratorSyntax)
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\VisualBasic\LanguageServices\InitializeParameter\InitializeParameterHelpers.vb (1)
45Return GetStatements(blockStatementOpt.Syntax).LastOrDefault()
Microsoft.CodeAnalysis.VisualBasic.Features (10)
ConvertIfToSwitch\VisualBasicConvertIfToSwitchCodeRefactoringProvider.Analyzer.vb (2)
19Dim statements = operation.Syntax.GetStatements() 24Select Case operation.Syntax.Kind
ConvertIfToSwitch\VisualBasicConvertIfToSwitchCodeRefactoringProvider.Rewriting.vb (1)
31Dim node = operation.Syntax
src\Analyzers\VisualBasic\Analyzers\ConvertTypeofToNameof\VisualBasicConvertTypeOfToNameOfDiagnosticAnalyzer.vb (1)
22Dim node = context.Operation.Syntax
src\Analyzers\VisualBasic\Analyzers\QualifyMemberAccess\VisualBasicQualifyMemberAccessDiagnosticAnalyzer.vb (2)
41Dim unaryExpressionSyntax As UnaryExpressionSyntax = TryCast(operation.Syntax, UnaryExpressionSyntax) 46Return operation.Syntax.GetLocation()
src\Analyzers\VisualBasic\Analyzers\RemoveUnusedParametersAndValues\VisualBasicRemoveUnusedParametersAndValuesDiagnosticAnalyzer.vb (2)
50Return TryCast(expressionStatement.Syntax, CallStatementSyntax) IsNot Nothing 75Return unusedDefinition.Syntax.GetLocation()
src\Analyzers\VisualBasic\Analyzers\SimplifyInterpolation\VisualBasicSimplifyInterpolationHelpers.vb (1)
19Return operation.Syntax
src\Analyzers\VisualBasic\CodeFixes\UseConditionalExpression\VisualBasicUseConditionalExpressionForAssignmentCodeFixProvider.vb (1)
47Return DirectCast(declarator.Syntax.Parent, VariableDeclaratorSyntax)
Microsoft.CodeAnalysis.VisualBasic.Semantic.UnitTests (5)
Diagnostics\GetDiagnosticsTests.vb (5)
641AnalyzeNode(context.Operation.Syntax, context.ContainingSymbol, AddressOf context.ReportDiagnostic) 646context.ReportDiagnostic(CodeAnalysis.Diagnostic.Create(DescriptorForBlockEnd, operationBlock.Syntax.GetLocation())) 648If TryCast(operationBlock.Syntax, PropertyBlockSyntax) IsNot Nothing OrElse 649TryCast(operationBlock.Syntax, EventBlockSyntax) IsNot Nothing Then 650Throw New Exception($"Unexpected topmost node for operation block '{operationBlock.Syntax.Kind()}'")
Microsoft.CodeAnalysis.VisualBasic.Workspaces (1)
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\VisualBasic\LanguageServices\InitializeParameter\InitializeParameterHelpers.vb (1)
45Return GetStatements(blockStatementOpt.Syntax).LastOrDefault()
Microsoft.CodeAnalysis.Workspaces (14)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Extensions\AnalysisContextExtensions.cs (3)
187=> operationBlock.Syntax.FindNode(context.FilterSpan, findInTrivia, getInnermostNodeForTie); 193=> operationBlock.Syntax.FindNode(context.FilterSpan, findInTrivia, getInnermostNodeForTie); 199=> context.Operation.Syntax.FindNode(context.FilterSpan, findInTrivia, getInnermostNodeForTie);
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\FlowAnalysis\SymbolUsageAnalysis\SymbolUsageAnalysis.DataFlowAnalyzer.FlowGraphAnalysisData.cs (1)
194var dataFlow = operation.SemanticModel.AnalyzeDataFlow(operation.Syntax);
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\LanguageServices\InitializeParameter\AbstractInitializerParameterService.cs (2)
176return statement.Syntax; 181return statementIndex > 0 && blockStatement.Operations[statementIndex - 1] is { IsImplicit: false, Syntax: var priorSyntax }
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\Utilities\NullableHelpers.cs (8)
43semanticFacts, semanticModel, rootOperation, declaredSymbol, rootOperation.Syntax.Span, includeDeclaration: true, cancellationToken) == true; 67if (!span.IntersectsWith(operation.Syntax.Span)) 70if (span.Contains(operation.Syntax.Span) && 76assignmentOperation.Syntax.RawKind == semanticFacts.SyntaxFacts.SyntaxKinds.SimpleAssignmentExpression) 83var typeInfo = semanticModel.GetTypeInfo(assignmentOperation.Value.Syntax, cancellationToken); 99var foreachInfo = semanticFacts.GetForEachSymbols(semanticModel, forEachLoop.Syntax); 111var syntax = variableDeclarator.GetVariableInitializer()!.Value.Syntax; 120var typeInfo = semanticModel.GetTypeInfo(operation.Syntax, cancellationToken);
Microsoft.Interop.ComInterfaceGenerator (9)
Analyzers\RuntimeComApiUsageWithSourceGeneratedComAnalyzer.cs (9)
123operation.TargetMethod.ToMinimalDisplayString(operation.SemanticModel, operation.Syntax.SpanStart), 124targetType.ToMinimalDisplayString(operation.SemanticModel, operation.Syntax.SpanStart))); 163operation.Syntax.GetLocation())); 183operation.Syntax.GetLocation())); 193operation.Syntax.GetLocation())); 202IConversionOperation conversion => (conversion.Operand.Type, conversion.Operand.Syntax.GetLocation()), 203IOperation op => (op.Type, op.Syntax.GetLocation()) 210var invocationSyntax = (InvocationExpressionSyntax)invocation.Syntax; 237ITypeOfOperation typeOf => (typeOf.TypeOperand, ((TypeOfExpressionSyntax)typeOf.Syntax).Type.GetLocation()),
Microsoft.Interop.LibraryImportGenerator (7)
Analyzers\CustomMarshallerAttributeAnalyzer.cs (5)
652DiagnosticReporter managedTypeReporter = DiagnosticReporter.CreateForLocation(managedTypeArgument.Value.Syntax.GetLocation(), context.ReportDiagnostic); 657DiagnosticReporter managedTypeReporter = DiagnosticReporter.CreateForLocation(((TypeOfExpressionSyntax)managedTypeOfOp.Syntax).Type.GetLocation(), context.ReportDiagnostic); 673DiagnosticReporter marshallerTypeReporter = DiagnosticReporter.CreateForLocation(marshallerTypeArgument.Value.Syntax.GetLocation(), context.ReportDiagnostic); 678DiagnosticReporter marshallerTypeReporter = DiagnosticReporter.CreateForLocation(((TypeOfExpressionSyntax)marshallerTypeOfOp.Syntax).Type.GetLocation(), context.ReportDiagnostic); 692DiagnosticReporter marshalModeReporter = DiagnosticReporter.CreateForLocation(marshalModeArgument.Syntax.GetLocation(), context.ReportDiagnostic);
Analyzers\NativeMarshallingAttributeAnalyzer.cs (2)
93DiagnosticReporter diagnosticFactory = DiagnosticReporter.CreateForLocation(marshallerEntryPointTypeArgument.Value.Syntax.GetLocation(), context.ReportDiagnostic); 102DiagnosticReporter.CreateForLocation(((TypeOfExpressionSyntax)typeOfOp.Syntax).Type.GetLocation(), context.ReportDiagnostic),
Roslyn.Compilers.VisualBasic.IOperation.UnitTests (2)
IOperation\IOperationTests_IUsingStatement.vb (2)
45Assert.NotNull(op.Resources.Syntax) 46Assert.Same(node.UsingStatement, op.Resources.Syntax)
System.Private.CoreLib.Generators (5)
IntrinsicsInSystemPrivateCoreLibAnalyzer.cs (5)
546context.ReportDiagnostic(Diagnostic.Create(RuleAttributeNotSpecificEnough, operation.Syntax.GetLocation(), attributeExplicitlyAllowsRelatedSymbol.ToDisplayString())); 566var ancestorNodes = operation.Syntax.AncestorsAndSelf(true); 613context.ReportDiagnostic(Diagnostic.Create(RuleCantParse, operation.Syntax.GetLocation())); 686context.ReportDiagnostic(Diagnostic.Create(Rule, operation.Syntax.GetLocation(), symbol.ContainingSymbol.ToDisplayString())); 688context.ReportDiagnostic(Diagnostic.Create(RuleHelper, operation.Syntax.GetLocation(), symbol.ToDisplayString()));
System.Text.RegularExpressions.Generator (5)
UpgradeToGeneratedRegexAnalyzer.cs (2)
111SyntaxNode? syntaxNodeForDiagnostic = invocationOperation.Syntax; 143SyntaxNode? syntaxNodeForDiagnostic = operation.Syntax;
UpgradeToGeneratedRegexCodeFixer.cs (3)
167.Select(arg => arg.Syntax); 292return literalOperation.Syntax; 297return generator.Argument(fieldReferenceOperation.Syntax);