Updated GetDeclaredVariables and comments with pr feedback.

上级 28d84520
......@@ -14,11 +14,13 @@ namespace Microsoft.CodeAnalysis.Semantics
public interface IVariableDeclaration : IOperation
{
/// <summary>
/// Symbols declared by the declaration.
/// Symbols declared by the declaration. In VB, it's possible to declare multiple variables with the
/// same initializer. In C#, this will always have a single symbol.
/// </summary>
ImmutableArray<ILocalSymbol> Variables { get; }
/// <summary>
/// Initializer of the variable.
/// Optional initializer of the variable.
/// </summary>
IOperation Initializer { get; }
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading;
using Roslyn.Utilities;
......@@ -46,15 +47,18 @@ public static IOperation GetRootOperation(this ISymbol symbol, CancellationToken
}
}
public static IEnumerable<ILocalSymbol> GetDeclaredVariables(this IVariableDeclarationStatement declarationStatement)
public static ImmutableArray<ILocalSymbol> GetDeclaredVariables(this IVariableDeclarationStatement declarationStatement)
{
var arrayBuilder = ArrayBuilder<ILocalSymbol>.GetInstance();
foreach (IVariableDeclaration group in declarationStatement.Declarations)
{
foreach (ILocalSymbol symbol in group.Variables)
{
yield return symbol;
arrayBuilder.Add(symbol);
}
}
return arrayBuilder.ToImmutableAndFree();
}
private sealed class OperationCollector : OperationWalker
......
......@@ -738,7 +738,7 @@ override Microsoft.CodeAnalysis.Semantics.OperationWalker.VisitYieldBreakStateme
static Microsoft.CodeAnalysis.Compilation.GetRequiredLanguageVersion(Microsoft.CodeAnalysis.Diagnostic diagnostic) -> string
static Microsoft.CodeAnalysis.Semantics.OperationExtensions.Descendants(this Microsoft.CodeAnalysis.IOperation operation) -> System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.IOperation>
static Microsoft.CodeAnalysis.Semantics.OperationExtensions.DescendantsAndSelf(this Microsoft.CodeAnalysis.IOperation operation) -> System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.IOperation>
static Microsoft.CodeAnalysis.Semantics.OperationExtensions.GetDeclaredVariables(this Microsoft.CodeAnalysis.Semantics.IVariableDeclarationStatement declarationStatement) -> System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.ILocalSymbol>
static Microsoft.CodeAnalysis.Semantics.OperationExtensions.GetDeclaredVariables(this Microsoft.CodeAnalysis.Semantics.IVariableDeclarationStatement declarationStatement) -> System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.ILocalSymbol>
static Microsoft.CodeAnalysis.Semantics.OperationExtensions.GetRootOperation(this Microsoft.CodeAnalysis.ISymbol symbol, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.IOperation
static Microsoft.CodeAnalysis.Semantics.UnaryAndBinaryOperationExtensions.GetBinaryOperandsKind(Microsoft.CodeAnalysis.Semantics.BinaryOperationKind kind) -> Microsoft.CodeAnalysis.Semantics.BinaryOperandsKind
static Microsoft.CodeAnalysis.Semantics.UnaryAndBinaryOperationExtensions.GetBinaryOperandsKind(this Microsoft.CodeAnalysis.Semantics.IBinaryOperatorExpression binary) -> Microsoft.CodeAnalysis.Semantics.BinaryOperandsKind
......
......@@ -820,7 +820,7 @@ public sealed override void Initialize(AnalysisContext context)
(operationContext) =>
{
var declarationStatement = (IVariableDeclarationStatement)operationContext.Operation;
if (declarationStatement.GetDeclaredSymbols().Count() > 3)
if (declarationStatement.GetDeclaredVariables().Count() > 3)
{
Report(operationContext, declarationStatement.Syntax, TooManyLocalVarDeclarationsDescriptor);
}
......@@ -1717,7 +1717,7 @@ public class NullOperationSyntaxTestAnalyzer : DiagnosticAnalyzer
DiagnosticSeverity.Warning,
isEnabledByDefault: true);
// since we don't expect to see the first diagnostic, we created this one to make sure
// since we don't expect to see the first diagnostic, we created this one to make sure
// the test didn't pass because the analyzer crashed.
public static readonly DiagnosticDescriptor ParamsArrayOperationDescriptor = new DiagnosticDescriptor(
"ParamsArray",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册