From f97b32d1e6a34d68eca0cbe07b8532fd0fc9bae9 Mon Sep 17 00:00:00 2001 From: RoslynTeam Date: Thu, 15 Jan 2015 15:59:12 -0800 Subject: [PATCH] Remove type parameter from RegisterCodeBlockEndAction methods. (changeset 1398588) --- .../Diagnostics/DiagnosticAnalyzerTests.cs | 4 +- .../AnalyzerDriver/AnalyzerDriverHelper.cs | 6 +- .../DiagnosticAnalyzerAction.cs | 2 +- .../DiagnosticStartAnalysisScope.cs | 68 +++++++++---------- .../DiagnosticAnalyzer/AnalyzerDriver.cs | 4 +- .../DiagnosticAnalysisContext.cs | 6 +- .../Diagnostics/TestDiagnosticAnalyzer.cs | 2 +- .../Diagnostics/DiagnosticAnalyzerTests.vb | 4 +- 8 files changed, 46 insertions(+), 50 deletions(-) diff --git a/src/Compilers/CSharp/Test/Semantic/Diagnostics/DiagnosticAnalyzerTests.cs b/src/Compilers/CSharp/Test/Semantic/Diagnostics/DiagnosticAnalyzerTests.cs index 8650c5d34c8..2e95aa381de 100644 --- a/src/Compilers/CSharp/Test/Semantic/Diagnostics/DiagnosticAnalyzerTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Diagnostics/DiagnosticAnalyzerTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// 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; using System.Collections.Generic; @@ -658,7 +658,7 @@ public override ImmutableArray SupportedDiagnostics public override void Initialize(AnalysisContext context) { context.RegisterCodeBlockStartAction(new NodeAnalyzer().Initialize); - context.RegisterCodeBlockEndAction(OnCodeBlockEnded); + context.RegisterCodeBlockEndAction(OnCodeBlockEnded); } public static void OnCodeBlockEnded(CodeBlockEndAnalysisContext context) diff --git a/src/Compilers/Core/AnalyzerDriver/AnalyzerDriverHelper.cs b/src/Compilers/Core/AnalyzerDriver/AnalyzerDriverHelper.cs index 7bae72425dc..15ae530cc6c 100644 --- a/src/Compilers/Core/AnalyzerDriver/AnalyzerDriverHelper.cs +++ b/src/Compilers/Core/AnalyzerDriver/AnalyzerDriverHelper.cs @@ -302,7 +302,7 @@ internal class AnalyzerDriverHelper VerifyArguments(declarationsInNode, getKind, semanticModel, actions, analyzerOptions, addDiagnostic, continueOnAnalyzerException); var codeBlockStartActions = actions.GetCodeBlockStartActions(); - var codeBlockEndActions = actions.GetCodeBlockEndActions(); + var codeBlockEndActions = actions.CodeBlockEndActions; if (!codeBlockStartActions.Any() && !codeBlockEndActions.Any()) { @@ -325,7 +325,7 @@ internal class AnalyzerDriverHelper internal static void ExecuteCodeBlockActions( IEnumerable> codeBlockStartActions, - IEnumerable> codeBlockEndActions, + IEnumerable codeBlockEndActions, SyntaxNode declaredNode, ISymbol declaredSymbol, ImmutableArray executableCodeBlocks, @@ -344,7 +344,7 @@ internal class AnalyzerDriverHelper Debug.Assert(executableCodeBlocks.Any()); // Compute the sets of code block end and stateful syntax node actions. - var endedActions = PooledHashSet>.GetInstance(); + var endedActions = PooledHashSet.GetInstance(); var executableNodeActions = ArrayBuilder>.GetInstance(); // Include the stateless code block actions. diff --git a/src/Compilers/Core/AnalyzerDriver/DiagnosticAnalyzerAction.cs b/src/Compilers/Core/AnalyzerDriver/DiagnosticAnalyzerAction.cs index f2b84d1bd43..0dd662e9722 100644 --- a/src/Compilers/Core/AnalyzerDriver/DiagnosticAnalyzerAction.cs +++ b/src/Compilers/Core/AnalyzerDriver/DiagnosticAnalyzerAction.cs @@ -114,7 +114,7 @@ public CodeBlockStartAnalyzerAction(Action> Action { get { return this.action; } } } - internal sealed class CodeBlockEndAnalyzerAction : AnalyzerAction where TLanguageKindEnum : struct + internal sealed class CodeBlockEndAnalyzerAction : AnalyzerAction { private readonly Action action; diff --git a/src/Compilers/Core/AnalyzerDriver/DiagnosticStartAnalysisScope.cs b/src/Compilers/Core/AnalyzerDriver/DiagnosticStartAnalysisScope.cs index 26550d3cd13..b3169916fca 100644 --- a/src/Compilers/Core/AnalyzerDriver/DiagnosticStartAnalysisScope.cs +++ b/src/Compilers/Core/AnalyzerDriver/DiagnosticStartAnalysisScope.cs @@ -58,10 +58,10 @@ public override void RegisterCodeBlockStartAction(Action(this.analyzer, action); } - public override void RegisterCodeBlockEndAction(Action action) + public override void RegisterCodeBlockEndAction(Action action) { DiagnosticAnalysisContextHelpers.VerifyArguments(action); - this.scope.RegisterCodeBlockEndAction(this.analyzer, action); + this.scope.RegisterCodeBlockEndAction(this.analyzer, action); } public override void RegisterSyntaxNodeAction(Action action, ImmutableArray syntaxKinds) @@ -111,9 +111,9 @@ public override void RegisterCodeBlockStartAction(Action(this.analyzer, action); } - public override void RegisterCodeBlockEndAction(Action action) + public override void RegisterCodeBlockEndAction(Action action) { - this.scope.RegisterCodeBlockEndAction(this.analyzer, action); + this.scope.RegisterCodeBlockEndAction(this.analyzer, action); } public override void RegisterSyntaxNodeAction(Action action, ImmutableArray syntaxKinds) @@ -206,28 +206,26 @@ public override ImmutableArray SymbolActions get { return base.SymbolActions.AddRange(this.sessionScope.SymbolActions); } } - public override bool HasCodeBlockStartActions() + public override ImmutableArray CodeBlockEndActions { - return - base.HasCodeBlockStartActions() || - this.sessionScope.HasCodeBlockStartActions(); + get { return base.CodeBlockEndActions.AddRange(this.sessionScope.CodeBlockEndActions); } } - public override ImmutableArray> GetCodeBlockStartActions() + public override bool HasCodeBlockEndActions { - return base.GetCodeBlockStartActions().AddRange(this.sessionScope.GetCodeBlockStartActions()); + get { return base.HasCodeBlockEndActions || this.sessionScope.HasCodeBlockEndActions; } } - public override bool HasCodeBlockEndActions() + public override bool HasCodeBlockStartActions() { return - base.HasCodeBlockEndActions() || - this.sessionScope.HasCodeBlockEndActions(); + base.HasCodeBlockStartActions() || + this.sessionScope.HasCodeBlockStartActions(); } - public override ImmutableArray> GetCodeBlockEndActions() + public override ImmutableArray> GetCodeBlockStartActions() { - return base.GetCodeBlockEndActions().AddRange(this.sessionScope.GetCodeBlockEndActions()); + return base.GetCodeBlockStartActions().AddRange(this.sessionScope.GetCodeBlockStartActions()); } public override ImmutableArray> GetSyntaxNodeActions() @@ -259,10 +257,10 @@ public override AnalyzerActions GetAnalyzerActions(DiagnosticAnalyzer analyzer) /// internal sealed class HostCodeBlockStartAnalysisScope where TLanguageKindEnum : struct { - private ImmutableArray> codeBlockEndActions = ImmutableArray>.Empty; + private ImmutableArray codeBlockEndActions = ImmutableArray.Empty; private ImmutableArray> syntaxNodeActions = ImmutableArray>.Empty; - public ImmutableArray> CodeBlockEndActions + public ImmutableArray CodeBlockEndActions { get { return this.codeBlockEndActions; } } @@ -278,7 +276,7 @@ internal HostCodeBlockStartAnalysisScope() public void RegisterCodeBlockEndAction(DiagnosticAnalyzer analyzer, Action action) { - this.codeBlockEndActions = this.codeBlockEndActions.Add(new CodeBlockEndAnalyzerAction(action, analyzer)); + this.codeBlockEndActions = this.codeBlockEndActions.Add(new CodeBlockEndAnalyzerAction(action, analyzer)); } public void RegisterSyntaxNodeAction(DiagnosticAnalyzer analyzer, Action action, ImmutableArray syntaxKinds) @@ -294,7 +292,7 @@ internal abstract class HostAnalysisScope private ImmutableArray syntaxTreeActions = ImmutableArray.Empty; private ImmutableArray symbolActions = ImmutableArray.Empty; private ImmutableArray codeBlockStartActions = ImmutableArray.Empty; - private ImmutableArray codeBlockEndActions = ImmutableArray.Empty; + private ImmutableArray codeBlockEndActions = ImmutableArray.Empty; private ImmutableArray syntaxNodeActions = ImmutableArray.Empty; private readonly Dictionary analyzerActions = new Dictionary(); @@ -318,24 +316,24 @@ public virtual ImmutableArray SymbolActions get { return this.symbolActions; } } - public virtual bool HasCodeBlockStartActions() where TLanguageKindEnum : struct + public virtual ImmutableArray CodeBlockEndActions { - return this.codeBlockStartActions.OfType>().Any(); + get { return this.codeBlockEndActions; } } - public virtual ImmutableArray> GetCodeBlockStartActions() where TLanguageKindEnum : struct + public virtual bool HasCodeBlockEndActions { - return this.codeBlockStartActions.OfType>().AsImmutable(); + get { return this.codeBlockEndActions.Any(); } } - public virtual bool HasCodeBlockEndActions() where TLanguageKindEnum : struct + public virtual bool HasCodeBlockStartActions() where TLanguageKindEnum : struct { - return this.codeBlockEndActions.OfType>().Any(); + return this.codeBlockStartActions.OfType>().Any(); } - public virtual ImmutableArray> GetCodeBlockEndActions() where TLanguageKindEnum : struct + public virtual ImmutableArray> GetCodeBlockStartActions() where TLanguageKindEnum : struct { - return this.codeBlockEndActions.OfType>().AsImmutable(); + return this.codeBlockStartActions.OfType>().AsImmutable(); } public virtual ImmutableArray> GetSyntaxNodeActions() where TLanguageKindEnum : struct @@ -385,9 +383,9 @@ public void RegisterSymbolAction(DiagnosticAnalyzer analyzer, Action(DiagnosticAnalyzer analyzer, Action action) where TLanguageKindEnum : struct + public void RegisterCodeBlockEndAction(DiagnosticAnalyzer analyzer, Action action) { - CodeBlockEndAnalyzerAction analyzerAction = new CodeBlockEndAnalyzerAction(action, analyzer); + CodeBlockEndAnalyzerAction analyzerAction = new CodeBlockEndAnalyzerAction(action, analyzer); this.GetOrCreateAnalyzerActions(analyzer).AddCodeBlockEndAction(analyzerAction); this.codeBlockEndActions = this.codeBlockEndActions.Add(analyzerAction); } @@ -427,7 +425,7 @@ internal sealed class AnalyzerActions private ImmutableArray semanticModelActions = ImmutableArray.Empty; private ImmutableArray symbolActions = ImmutableArray.Empty; private ImmutableArray codeBlockStartActions = ImmutableArray.Empty; - private ImmutableArray codeBlockEndActions = ImmutableArray.Empty; + private ImmutableArray codeBlockEndActions = ImmutableArray.Empty; private ImmutableArray syntaxNodeActions = ImmutableArray.Empty; internal AnalyzerActions() @@ -468,14 +466,14 @@ internal ImmutableArray SymbolActions get { return this.symbolActions; } } - internal ImmutableArray> GetCodeBlockStartActions() where TLanguageKindEnum : struct + internal ImmutableArray CodeBlockEndActions { - return this.codeBlockStartActions.OfType>().ToImmutableArray(); + get { return this.codeBlockEndActions; } } - internal ImmutableArray> GetCodeBlockEndActions() where TLanguageKindEnum : struct + internal ImmutableArray> GetCodeBlockStartActions() where TLanguageKindEnum : struct { - return this.codeBlockEndActions.OfType>().ToImmutableArray(); + return this.codeBlockStartActions.OfType>().ToImmutableArray(); } internal ImmutableArray> GetSyntaxNodeActions() where TLanguageKindEnum : struct @@ -513,7 +511,7 @@ internal void AddSymbolAction(SymbolAnalyzerAction action) this.codeBlockStartActions = this.codeBlockStartActions.Add(action); } - internal void AddCodeBlockEndAction(CodeBlockEndAnalyzerAction action) where TLanguageKindEnum : struct + internal void AddCodeBlockEndAction(CodeBlockEndAnalyzerAction action) { this.codeBlockEndActions = this.codeBlockEndActions.Add(action); } diff --git a/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerDriver.cs b/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerDriver.cs index 7c46914096c..1f1f34d4908 100644 --- a/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerDriver.cs +++ b/src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerDriver.cs @@ -772,7 +772,7 @@ protected override async Task AnalyzeDeclaringReferenceAsync(SymbolDeclaredCompi var statelessNodeActionsByKind = this.NodeActionsByKind; var executeSyntaxNodeActions = statelessNodeActionsByKind.Any(); - var executeCodeBlockActions = AnalyzerDriverHelper.CanHaveExecutableCodeBlock(symbol) && (this.compilationAnalysisScope.HasCodeBlockStartActions() || this.compilationAnalysisScope.HasCodeBlockEndActions()); + var executeCodeBlockActions = AnalyzerDriverHelper.CanHaveExecutableCodeBlock(symbol) && (this.compilationAnalysisScope.HasCodeBlockStartActions() || this.compilationAnalysisScope.HasCodeBlockEndActions); if (executeSyntaxNodeActions || executeCodeBlockActions) { @@ -936,7 +936,7 @@ protected override async Task AnalyzeDeclaringReferenceAsync(SymbolDeclaredCompi { AnalyzerDriverHelper.ExecuteCodeBlockActions( compilationScope.GetCodeBlockStartActions(), - compilationScope.GetCodeBlockEndActions(), + compilationScope.CodeBlockEndActions, declaredNode, declaredSymbol, executableCodeBlocks, diff --git a/src/Compilers/Core/Portable/DiagnosticAnalyzer/DiagnosticAnalysisContext.cs b/src/Compilers/Core/Portable/DiagnosticAnalyzer/DiagnosticAnalysisContext.cs index 46cf49e89c5..c1bf5262606 100644 --- a/src/Compilers/Core/Portable/DiagnosticAnalyzer/DiagnosticAnalysisContext.cs +++ b/src/Compilers/Core/Portable/DiagnosticAnalyzer/DiagnosticAnalysisContext.cs @@ -93,9 +93,8 @@ public void RegisterSymbolAction(Action action, params Sy /// Register an action to be executed at the end of semantic analysis of a method body or an expression appearing outside a method body. /// A code block end action reports s about code blocks. /// - /// Enum type giving the syntax node kinds of the source language for which the action applies. /// Action to be executed at the end of semantic analysis of a code block. - public abstract void RegisterCodeBlockEndAction(Action action) where TLanguageKindEnum : struct; + public abstract void RegisterCodeBlockEndAction(Action action); /// /// Register an action to be executed at completion of parsing of a code document. @@ -230,9 +229,8 @@ public void RegisterSymbolAction(Action action, params Sy /// Register an action to be executed at the end of semantic analysis of a method body or an expression appearing outside a method body. /// A code block end action reports s about code blocks. /// - /// Enum type giving the syntax node kinds of the source language for which the action applies. /// Action to be executed at the end of semantic analysis of a code block. - public abstract void RegisterCodeBlockEndAction(Action action) where TLanguageKindEnum : struct; + public abstract void RegisterCodeBlockEndAction(Action action); /// /// Register an action to be executed at completion of parsing of a code document. diff --git a/src/Compilers/Test/Utilities/Core2/Diagnostics/TestDiagnosticAnalyzer.cs b/src/Compilers/Test/Utilities/Core2/Diagnostics/TestDiagnosticAnalyzer.cs index bf8ebface07..c68b0b9e170 100644 --- a/src/Compilers/Test/Utilities/Core2/Diagnostics/TestDiagnosticAnalyzer.cs +++ b/src/Compilers/Test/Utilities/Core2/Diagnostics/TestDiagnosticAnalyzer.cs @@ -48,7 +48,7 @@ public override void Initialize(AnalysisContext context) context.RegisterCompilationEndAction(this.AnalyzeCompilation); context.RegisterSemanticModelAction(this.AnalyzeSemanticModel); - context.RegisterCodeBlockEndAction(this.AnalyzeCodeBlock); + context.RegisterCodeBlockEndAction(this.AnalyzeCodeBlock); context.RegisterSymbolAction(this.AnalyzeSymbol, AllSymbolKinds.ToArray()); context.RegisterSyntaxTreeAction(this.AnalyzeSyntaxTree); context.RegisterSyntaxNodeAction(this.AnalyzeNode, AllSyntaxKinds.ToArray()); diff --git a/src/Compilers/VisualBasic/Test/Semantic/Diagnostics/DiagnosticAnalyzerTests.vb b/src/Compilers/VisualBasic/Test/Semantic/Diagnostics/DiagnosticAnalyzerTests.vb index 2d383ba9fd4..77bfd19338d 100644 --- a/src/Compilers/VisualBasic/Test/Semantic/Diagnostics/DiagnosticAnalyzerTests.vb +++ b/src/Compilers/VisualBasic/Test/Semantic/Diagnostics/DiagnosticAnalyzerTests.vb @@ -1,4 +1,4 @@ -' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. Imports System.Collections.Immutable Imports System.Globalization @@ -532,7 +532,7 @@ End Namespace End Property Public Overrides Sub Initialize(context As AnalysisContext) - context.RegisterCodeBlockEndAction(Of SyntaxKind)(AddressOf OnCodeBlock) + context.RegisterCodeBlockEndAction(AddressOf OnCodeBlock) End Sub Private Shared Sub OnCodeBlock(context As CodeBlockEndAnalysisContext) -- GitLab