diff --git a/src/Analyzers/CSharp/CodeFixes/CSharpCodeFixes.projitems b/src/Analyzers/CSharp/CodeFixes/CSharpCodeFixes.projitems index dbcbcb60707f9..95d599441af66 100644 --- a/src/Analyzers/CSharp/CodeFixes/CSharpCodeFixes.projitems +++ b/src/Analyzers/CSharp/CodeFixes/CSharpCodeFixes.projitems @@ -48,6 +48,7 @@ + diff --git a/src/Features/CSharp/Portable/ImplementAbstractClass/CSharpImplementAbstractClassCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/ImplementAbstractClass/CSharpImplementAbstractClassCodeFixProvider.cs similarity index 94% rename from src/Features/CSharp/Portable/ImplementAbstractClass/CSharpImplementAbstractClassCodeFixProvider.cs rename to src/Analyzers/CSharp/CodeFixes/ImplementAbstractClass/CSharpImplementAbstractClassCodeFixProvider.cs index 89d58bf473ab2..aa7db53519afc 100644 --- a/src/Features/CSharp/Portable/ImplementAbstractClass/CSharpImplementAbstractClassCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/ImplementAbstractClass/CSharpImplementAbstractClassCodeFixProvider.cs @@ -12,7 +12,7 @@ namespace Microsoft.CodeAnalysis.CSharp.ImplementAbstractClass; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ImplementAbstractClass), Shared] [ExtensionOrder(After = PredefinedCodeFixProviderNames.GenerateType)] -internal class CSharpImplementAbstractClassCodeFixProvider : +internal sealed class CSharpImplementAbstractClassCodeFixProvider : AbstractImplementAbstractClassCodeFixProvider { private const string CS0534 = nameof(CS0534); // 'Program' does not implement inherited abstract member 'Goo.bar()' diff --git a/src/Analyzers/CSharp/Tests/CSharpAnalyzers.UnitTests.projitems b/src/Analyzers/CSharp/Tests/CSharpAnalyzers.UnitTests.projitems index 4cb24a2e90359..fdb450f9505a6 100644 --- a/src/Analyzers/CSharp/Tests/CSharpAnalyzers.UnitTests.projitems +++ b/src/Analyzers/CSharp/Tests/CSharpAnalyzers.UnitTests.projitems @@ -34,6 +34,9 @@ + + + diff --git a/src/Features/CSharpTest/ImplementAbstractClass/ImplementAbstractClassTests.cs b/src/Analyzers/CSharp/Tests/ImplementAbstractClass/ImplementAbstractClassTests.cs similarity index 100% rename from src/Features/CSharpTest/ImplementAbstractClass/ImplementAbstractClassTests.cs rename to src/Analyzers/CSharp/Tests/ImplementAbstractClass/ImplementAbstractClassTests.cs diff --git a/src/Features/CSharpTest/ImplementAbstractClass/ImplementAbstractClassTests_FixAllTests.cs b/src/Analyzers/CSharp/Tests/ImplementAbstractClass/ImplementAbstractClassTests_FixAllTests.cs similarity index 100% rename from src/Features/CSharpTest/ImplementAbstractClass/ImplementAbstractClassTests_FixAllTests.cs rename to src/Analyzers/CSharp/Tests/ImplementAbstractClass/ImplementAbstractClassTests_FixAllTests.cs diff --git a/src/Features/CSharpTest/ImplementAbstractClass/ImplementAbstractClassTests_ThroughMember.cs b/src/Analyzers/CSharp/Tests/ImplementAbstractClass/ImplementAbstractClassTests_ThroughMember.cs similarity index 90% rename from src/Features/CSharpTest/ImplementAbstractClass/ImplementAbstractClassTests_ThroughMember.cs rename to src/Analyzers/CSharp/Tests/ImplementAbstractClass/ImplementAbstractClassTests_ThroughMember.cs index 72af868c1c1a3..7367bb8976b80 100644 --- a/src/Features/CSharpTest/ImplementAbstractClass/ImplementAbstractClassTests_ThroughMember.cs +++ b/src/Analyzers/CSharp/Tests/ImplementAbstractClass/ImplementAbstractClassTests_ThroughMember.cs @@ -72,7 +72,7 @@ abstract class Base class [|Derived|] : Base { } - """, [FeaturesResources.Implement_abstract_class]); + """, [AnalyzersResources.Implement_abstract_class]); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41420")] @@ -93,7 +93,7 @@ abstract class Middle : Base class [|Derived|] : Base { } - """, [FeaturesResources.Implement_abstract_class]); + """, [AnalyzersResources.Implement_abstract_class]); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41420")] @@ -126,7 +126,7 @@ public override void Method() inner.Method(); } } - """, index: 1, title: string.Format(FeaturesResources.Implement_through_0, "inner")); + """, index: 1, title: string.Format(AnalyzersResources.Implement_through_0, "inner")); } [Fact] @@ -159,7 +159,7 @@ public override void Method(int a, ref int b, in int c, ref readonly int d, out inner.Method(a, ref b, c, in d, out e); } } - """, index: 1, title: string.Format(FeaturesResources.Implement_through_0, "inner")); + """, index: 1, title: string.Format(AnalyzersResources.Implement_through_0, "inner")); } [Fact] @@ -189,7 +189,7 @@ class Derived : Base public override int this[int a, in int b, ref readonly int c, out int d] => inner[a, b, in c, out d]; } - """, index: 1, title: string.Format(FeaturesResources.Implement_through_0, "inner")); + """, index: 1, title: string.Format(AnalyzersResources.Implement_through_0, "inner")); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41420")] @@ -224,7 +224,7 @@ public override void Method1() inner.Method1(); } } - """, index: 1, title: string.Format(FeaturesResources.Implement_through_0, "inner")); + """, index: 1, title: string.Format(AnalyzersResources.Implement_through_0, "inner")); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41420")] @@ -247,7 +247,7 @@ public override void Method1() inner.Method1(); } } - """, new string[] { FeaturesResources.Implement_abstract_class }); + """, new string[] { AnalyzersResources.Implement_abstract_class }); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41420")] @@ -288,7 +288,7 @@ public override void Method() class DerivedAgain : Derived { } - """, index: 1, title: string.Format(FeaturesResources.Implement_through_0, "inner")); + """, index: 1, title: string.Format(AnalyzersResources.Implement_through_0, "inner")); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41420")] @@ -321,7 +321,7 @@ public override void Method() inner.Method(); } } - """, index: 1, title: string.Format(FeaturesResources.Implement_through_0, "inner")); + """, index: 1, title: string.Format(AnalyzersResources.Implement_through_0, "inner")); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41420")] @@ -347,9 +347,9 @@ class [|Derived|] : Base, IInterface } """, [ - FeaturesResources.Implement_abstract_class, - string.Format(FeaturesResources.Implement_through_0, "Inner"), - string.Format(FeaturesResources.Implement_through_0, "IInterface.Inner"), + AnalyzersResources.Implement_abstract_class, + string.Format(AnalyzersResources.Implement_through_0, "Inner"), + string.Format(AnalyzersResources.Implement_through_0, "IInterface.Inner"), ]); } @@ -367,7 +367,7 @@ class [|Derived|] : Base { dynamic inner; } - """, [FeaturesResources.Implement_abstract_class]); + """, [AnalyzersResources.Implement_abstract_class]); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41420")] @@ -400,7 +400,7 @@ public override void Method() inner.Method(); } } - """, index: 1, title: string.Format(FeaturesResources.Implement_through_0, "inner")); + """, index: 1, title: string.Format(AnalyzersResources.Implement_through_0, "inner")); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41420")] @@ -430,7 +430,7 @@ class Derived : Base public override int Property { get => inner.Property; set => inner.Property = value; } } - """, index: 1, title: string.Format(FeaturesResources.Implement_through_0, "inner")); + """, index: 1, title: string.Format(AnalyzersResources.Implement_through_0, "inner")); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41420")] @@ -505,7 +505,7 @@ class Derived : Base public override int SetOnly { set => inner.SetOnly = value; } } - """, index: 1, title: string.Format(FeaturesResources.Implement_through_0, "inner")); + """, index: 1, title: string.Format(AnalyzersResources.Implement_through_0, "inner")); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41420")] @@ -596,7 +596,7 @@ public override event Action Event } } } - """, index: 1, title: string.Format(FeaturesResources.Implement_through_0, "inner")); + """, index: 1, title: string.Format(AnalyzersResources.Implement_through_0, "inner")); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41420")] @@ -633,7 +633,7 @@ public override void Method() inner.Method(); } } - """, index: 1, title: string.Format(FeaturesResources.Implement_through_0, "inner")); + """, index: 1, title: string.Format(AnalyzersResources.Implement_through_0, "inner")); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41420")] @@ -650,7 +650,7 @@ class [|Derived|] : Base { Base inner; } - """, [FeaturesResources.Implement_abstract_class]); + """, [AnalyzersResources.Implement_abstract_class]); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41420")] @@ -683,7 +683,7 @@ protected override void Method() inner.Method(); } } - """, index: 1, title: string.Format(FeaturesResources.Implement_through_0, "inner")); + """, index: 1, title: string.Format(AnalyzersResources.Implement_through_0, "inner")); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41420")] @@ -716,7 +716,7 @@ protected internal override void Method() inner.Method(); } } - """, index: 1, title: string.Format(FeaturesResources.Implement_through_0, "inner")); + """, index: 1, title: string.Format(AnalyzersResources.Implement_through_0, "inner")); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41420")] @@ -749,7 +749,7 @@ internal override void Method() inner.Method(); } } - """, index: 1, title: string.Format(FeaturesResources.Implement_through_0, "inner")); + """, index: 1, title: string.Format(AnalyzersResources.Implement_through_0, "inner")); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41420")] @@ -766,7 +766,7 @@ class [|Derived|] : Base { Base inner; } - """, [FeaturesResources.Implement_abstract_class]); + """, [AnalyzersResources.Implement_abstract_class]); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41420")] @@ -799,7 +799,7 @@ private protected override void Method() inner.Method(); } } - """, index: 1, title: string.Format(FeaturesResources.Implement_through_0, "inner")); + """, index: 1, title: string.Format(AnalyzersResources.Implement_through_0, "inner")); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41420")] @@ -832,7 +832,7 @@ class Derived : Base public override int InternalGet { internal get => inner.InternalGet; set => inner.InternalGet = value; } public override int InternalSet { get => inner.InternalSet; internal set => inner.InternalSet = value; } } - """, index: 1, title: string.Format(FeaturesResources.Implement_through_0, "inner")); + """, index: 1, title: string.Format(AnalyzersResources.Implement_through_0, "inner")); } [Fact] @@ -935,7 +935,7 @@ class [|Program|](Base base1) : Base { private Base _base = base1; } - """, [FeaturesResources.Implement_abstract_class, string.Format(FeaturesResources.Implement_through_0, "_base")]); + """, [AnalyzersResources.Implement_abstract_class, string.Format(AnalyzersResources.Implement_through_0, "_base")]); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/69177")] @@ -953,7 +953,7 @@ class [|Program|](Base base1) : Base { private Base _base = (base1); } - """, [FeaturesResources.Implement_abstract_class, string.Format(FeaturesResources.Implement_through_0, "_base")]); + """, [AnalyzersResources.Implement_abstract_class, string.Format(AnalyzersResources.Implement_through_0, "_base")]); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/69177")] @@ -971,7 +971,7 @@ class [|Program|](Base base1) : Base { private Base B { get; } = base1; } - """, [FeaturesResources.Implement_abstract_class, string.Format(FeaturesResources.Implement_through_0, "B")]); + """, [AnalyzersResources.Implement_abstract_class, string.Format(AnalyzersResources.Implement_through_0, "B")]); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/69177")] @@ -989,7 +989,7 @@ class [|Program|](Base base1) : Base { private Base B { get; } = (base1); } - """, [FeaturesResources.Implement_abstract_class, string.Format(FeaturesResources.Implement_through_0, "B")]); + """, [AnalyzersResources.Implement_abstract_class, string.Format(AnalyzersResources.Implement_through_0, "B")]); } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/69177")] diff --git a/src/Analyzers/Core/Analyzers/AnalyzersResources.resx b/src/Analyzers/Core/Analyzers/AnalyzersResources.resx index df9dabaf42ade..34ab80d6e554e 100644 --- a/src/Analyzers/Core/Analyzers/AnalyzersResources.resx +++ b/src/Analyzers/Core/Analyzers/AnalyzersResources.resx @@ -397,4 +397,13 @@ Simplify check - + + Base classes contain inaccessible unimplemented members + + + Implement abstract class + + + Implement through '{0}' + + \ No newline at end of file diff --git a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.cs.xlf b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.cs.xlf index 783b82502cec7..4e9d5e4bc1703 100644 --- a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.cs.xlf +++ b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.cs.xlf @@ -96,6 +96,11 @@ Vyhněte se v kódu nepoužitým parametrům. Pokud parametr nelze odebrat, změňte jeho název tak, aby začínal podtržítkem, za kterým volitelně následuje celé číslo, například _, _1, _2 atd. Tyto řetězce se považují za názvy speciálních symbolů pro vyřazení. + + Base classes contain inaccessible unimplemented members + Base classes contain inaccessible unimplemented members + + Blank line required between block and subsequent statement Mezi blokem a následným příkazem se vyžaduje prázdný řádek. @@ -146,6 +151,16 @@ Implementace GetHashCode může být zjednodušená. + + Implement abstract class + Implement abstract class + + + + Implement through '{0}' + Implement through '{0}' + + Interpolation can be simplified Interpolace může být zjednodušená. diff --git a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.de.xlf b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.de.xlf index ad65305a6d402..9aab7ea52155d 100644 --- a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.de.xlf +++ b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.de.xlf @@ -96,6 +96,11 @@ Vermeiden Sie nicht verwendete Parameter in Ihrem Code. Wenn der Parameter nicht entfernt werden kann, ändern Sie dessen Namen so, dass er mit einem Unterstrich beginnt, dem optional eine Zahl angefügt wird. Beispiel: "_", "_1", "_2" usw. Diese werden als spezielle Symbolnamen für Ausschussparameter behandelt. + + Base classes contain inaccessible unimplemented members + Base classes contain inaccessible unimplemented members + + Blank line required between block and subsequent statement Zwischen dem Block und der nachfolgenden Anweisung ist eine leere Zeile erforderlich. @@ -146,6 +151,16 @@ Die Implementierung von "GetHashCode" kann vereinfacht werden. + + Implement abstract class + Implement abstract class + + + + Implement through '{0}' + Implement through '{0}' + + Interpolation can be simplified Die Interpolation kann vereinfacht werden diff --git a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.es.xlf b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.es.xlf index b0f143d75f44e..980c2ac06750d 100644 --- a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.es.xlf +++ b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.es.xlf @@ -96,6 +96,11 @@ Evite los parámetros sin usar en el código. Si el parámetro no se puede quitar, cámbielo de nombre para que empiece por un carácter de subrayado, seguido opcionalmente por un entero, como "_", "_1", "_2", etc. Estos se tratan como nombres de símbolos de descarte especiales. + + Base classes contain inaccessible unimplemented members + Base classes contain inaccessible unimplemented members + + Blank line required between block and subsequent statement Se requiere una línea en blanco entre el bloque y la instrucción subsiguiente @@ -146,6 +151,16 @@ La implementación de "GetHashCode" se puede simplificar. + + Implement abstract class + Implement abstract class + + + + Implement through '{0}' + Implement through '{0}' + + Interpolation can be simplified La interpolación se puede simplificar diff --git a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.fr.xlf b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.fr.xlf index a104342f0da5b..1cf1460fe34bb 100644 --- a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.fr.xlf +++ b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.fr.xlf @@ -96,6 +96,11 @@ Évitez les paramètres inutilisés dans votre code. Évitez les paramètres inutilisés dans votre code. Si vous ne pouvez pas supprimer un paramètre, changez son nom en le faisant commencer par un trait de soulignement éventuellement suivi d'un entier, par exemple '_', '_1', '_2', etc. Ces types d'élément sont traités en tant que noms de symboles discard spéciaux. + + Base classes contain inaccessible unimplemented members + Base classes contain inaccessible unimplemented members + + Blank line required between block and subsequent statement Ligne vide nécessaire entre le bloc et l'instruction qui suit @@ -146,6 +151,16 @@ L'implémentation de 'GetHashCode' peut être simplifiée + + Implement abstract class + Implement abstract class + + + + Implement through '{0}' + Implement through '{0}' + + Interpolation can be simplified L'interpolation peut être simplifiée diff --git a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.it.xlf b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.it.xlf index 3dd221c998368..6a995a06a8700 100644 --- a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.it.xlf +++ b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.it.xlf @@ -96,6 +96,11 @@ Evitare parametri inutilizzati nel codice. Se non è possibile rimuovere il parametro, modificarne il nome in modo che inizi con un carattere di sottolineatura e, facoltativamente, sia seguito da un numero intero, ad esempio '_', '_1', '_2' e così via. Questi vengono considerati come nomi di simboli speciali di rimozione. + + Base classes contain inaccessible unimplemented members + Base classes contain inaccessible unimplemented members + + Blank line required between block and subsequent statement È richiesta una riga vuota tra il blocco e l'istruzione successiva @@ -146,6 +151,16 @@ L'implementazione di 'GetHashCode' può essere semplificata + + Implement abstract class + Implement abstract class + + + + Implement through '{0}' + Implement through '{0}' + + Interpolation can be simplified L'interpolazione può essere semplificata diff --git a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.ja.xlf b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.ja.xlf index 187e5e137d9f7..e9ab67f02392d 100644 --- a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.ja.xlf +++ b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.ja.xlf @@ -97,6 +97,11 @@ コードに未使用のパラメーターを指定しないでください。パラメーターを削除できない場合は、パラメーターの名前をアンダースコアの後にオプションで整数が続く名前 ('_'、'_1'、'_2' など) に変更してください。これらは、特別なディスカード シンボル名として扱われます。 + + Base classes contain inaccessible unimplemented members + Base classes contain inaccessible unimplemented members + + Blank line required between block and subsequent statement ブロックと後続のステートメントの間に空白行が必要です @@ -147,6 +152,16 @@ 'GetHashCode' の実装を簡素化できます + + Implement abstract class + Implement abstract class + + + + Implement through '{0}' + Implement through '{0}' + + Interpolation can be simplified 補間を簡素化することができます diff --git a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.ko.xlf b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.ko.xlf index bf7482fa9dac3..736cf4bcd2356 100644 --- a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.ko.xlf +++ b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.ko.xlf @@ -96,6 +96,11 @@ 코드에 사용되지 않는 매개 변수를 사용하지 않도록 합니다. 매개 변수를 제거할 수 없는 경우 이름을 변경하여 밑줄로 시작하고 필요에 따라 뒤에 정수가 있도록 합니다(예: '_', '_1', '_2' 등). 해당 이름은 특수 무시 기호 이름으로 처리됩니다. + + Base classes contain inaccessible unimplemented members + Base classes contain inaccessible unimplemented members + + Blank line required between block and subsequent statement 블록과 후속 문 사이에 빈 줄이 필요함 @@ -146,6 +151,16 @@ 'GetHashCode' 구현을 단순화할 수 있습니다. + + Implement abstract class + Implement abstract class + + + + Implement through '{0}' + Implement through '{0}' + + Interpolation can be simplified 보간을 단순화할 수 있습니다. diff --git a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.pl.xlf b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.pl.xlf index 48f6db3801bcf..7d2881ef2938c 100644 --- a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.pl.xlf +++ b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.pl.xlf @@ -96,6 +96,11 @@ Unikaj nieużywanych parametrów w kodzie. Jeśli nie można usunąć parametru, zmień jego nazwę, tak aby rozpoczynała się od znaku podkreślenia, a opcjonalnie następowała po niej liczba całkowita, na przykład „_”, „_1”, „_2” itp. Są one traktowane jako specjalne nazwy symboli odrzucenia. + + Base classes contain inaccessible unimplemented members + Base classes contain inaccessible unimplemented members + + Blank line required between block and subsequent statement Wymagany jest pusty wiersz między blokiem a kolejną instrukcją @@ -146,6 +151,16 @@ Implementację „GetHashCode” można uprościć + + Implement abstract class + Implement abstract class + + + + Implement through '{0}' + Implement through '{0}' + + Interpolation can be simplified Interpolację można uprościć diff --git a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.pt-BR.xlf b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.pt-BR.xlf index 6bc52c076ab6f..efbd9b9f71ba1 100644 --- a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.pt-BR.xlf +++ b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.pt-BR.xlf @@ -96,6 +96,11 @@ Evite parâmetros não usados no seu código. Se o parâmetro não puder ser removido, altere o nome para que ele comece com um sublinhado e seja seguido opcionalmente por um inteiro, como '_', '_1', '_2' etc. Esses nomes são tratados como nomes de símbolo de descarte especiais. + + Base classes contain inaccessible unimplemented members + Base classes contain inaccessible unimplemented members + + Blank line required between block and subsequent statement Linha em branco necessária entre o bloco e a próxima instrução @@ -146,6 +151,16 @@ A implementação de 'GetHashCode' pode ser simplificada + + Implement abstract class + Implement abstract class + + + + Implement through '{0}' + Implement through '{0}' + + Interpolation can be simplified A interpolação pode ser simplificada diff --git a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.ru.xlf b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.ru.xlf index 4e8b7cd4df423..f7a626dc6dddb 100644 --- a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.ru.xlf +++ b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.ru.xlf @@ -96,6 +96,11 @@ Избегайте неиспользуемых параметров в коде. Если удалить параметр невозможно, измените его имя так, чтобы оно начиналось с символа подчеркивания, за которым при необходимости следует целое число, например, "_", "_1", "_2" и т. д. Эти имена считаются особыми пустыми именами символов. + + Base classes contain inaccessible unimplemented members + Base classes contain inaccessible unimplemented members + + Blank line required between block and subsequent statement Необходима пустая линия между блоком и следующим оператором. @@ -146,6 +151,16 @@ Реализацию GetHashCode можно упростить. + + Implement abstract class + Implement abstract class + + + + Implement through '{0}' + Implement through '{0}' + + Interpolation can be simplified Вы можете упростить интерполяцию. diff --git a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.tr.xlf b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.tr.xlf index cb77bb7ac663e..12b748d385da3 100644 --- a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.tr.xlf +++ b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.tr.xlf @@ -96,6 +96,11 @@ Kodunuzda kullanılmayan parametreler bulundurmamaya çalışın. Parametre kaldırılamıyorsa adını, bir alt çizgiyle başlayacak ve ardından isteğe bağlı olarak bir tamsayı gelecek ('_', '_1', '_2' gibi) şekilde değiştirin. Bu değerler özel atılabilir sembol adı olarak işlenir. + + Base classes contain inaccessible unimplemented members + Base classes contain inaccessible unimplemented members + + Blank line required between block and subsequent statement Blok ve sonraki ifade arasında boş satır gerekir @@ -146,6 +151,16 @@ 'GetHashCode' uygulaması basitleştirilebilir + + Implement abstract class + Implement abstract class + + + + Implement through '{0}' + Implement through '{0}' + + Interpolation can be simplified İlişkilendirme basitleştirilebilir diff --git a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.zh-Hans.xlf b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.zh-Hans.xlf index f5d7fc08b5ef2..dee55b2cb9077 100644 --- a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.zh-Hans.xlf +++ b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.zh-Hans.xlf @@ -96,6 +96,11 @@ 请避免在代码中使用未使用的参数。如果无法删除该参数,请更改其名称,使其以下划线开头,也可在下划线后面跟一个整数(如 "_"、"_1"、"_2" 等)。这些被视为特殊丢弃符号名。 + + Base classes contain inaccessible unimplemented members + Base classes contain inaccessible unimplemented members + + Blank line required between block and subsequent statement 块与后续语句之间需要有空白行 @@ -146,6 +151,16 @@ 可简化 "GetHashCode" 实现 + + Implement abstract class + Implement abstract class + + + + Implement through '{0}' + Implement through '{0}' + + Interpolation can be simplified 内插可以简化 diff --git a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.zh-Hant.xlf b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.zh-Hant.xlf index b69c3d9e738ad..1bb2545ebe4d5 100644 --- a/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.zh-Hant.xlf +++ b/src/Analyzers/Core/Analyzers/xlf/AnalyzersResources.zh-Hant.xlf @@ -96,6 +96,11 @@ 請避免在您的程式碼中使用參數。如果無法移除參數,請變更其名稱,使其以底線開頭,並可選擇在後面接著整數,例如 '_'、'_1'、'_2' 等。這些會視為特殊的捨棄符號名稱。 + + Base classes contain inaccessible unimplemented members + Base classes contain inaccessible unimplemented members + + Blank line required between block and subsequent statement 區塊與後續陳述式之間必須有空白行 @@ -146,6 +151,16 @@ 'GetHashCode' 實作可簡化 + + Implement abstract class + Implement abstract class + + + + Implement through '{0}' + Implement through '{0}' + + Interpolation can be simplified 可簡化內插補點 diff --git a/src/Analyzers/Core/CodeFixes/CodeFixes.projitems b/src/Analyzers/Core/CodeFixes/CodeFixes.projitems index 407477c962427..0a71a14392a30 100644 --- a/src/Analyzers/Core/CodeFixes/CodeFixes.projitems +++ b/src/Analyzers/Core/CodeFixes/CodeFixes.projitems @@ -37,6 +37,13 @@ + + + + + + + diff --git a/src/Features/Core/Portable/ImplementAbstractClass/AbstractImplementAbstractClassCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/ImplementAbstractClass/AbstractImplementAbstractClassCodeFixProvider.cs similarity index 91% rename from src/Features/Core/Portable/ImplementAbstractClass/AbstractImplementAbstractClassCodeFixProvider.cs rename to src/Analyzers/Core/CodeFixes/ImplementAbstractClass/AbstractImplementAbstractClassCodeFixProvider.cs index b96844c5298ff..89b813f459da6 100644 --- a/src/Features/Core/Portable/ImplementAbstractClass/AbstractImplementAbstractClassCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/ImplementAbstractClass/AbstractImplementAbstractClassCodeFixProvider.cs @@ -48,7 +48,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) var id = GetCodeActionId(abstractClassType.ContainingAssembly.Name, abstractClassType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)); context.RegisterCodeFix( CodeAction.Create( - FeaturesResources.Implement_abstract_class, + AnalyzersResources.Implement_abstract_class, c => data.ImplementAbstractClassAsync(throughMember: null, canDelegateAllMembers: null, c), id), context.Diagnostics); @@ -62,7 +62,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) context.RegisterCodeFix( CodeAction.Create( - string.Format(FeaturesResources.Implement_through_0, through.Name), + string.Format(AnalyzersResources.Implement_through_0, through.Name), c => data.ImplementAbstractClassAsync(through, canDelegateAllMembers, c), id), context.Diagnostics); @@ -70,5 +70,5 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) } private static string GetCodeActionId(string assemblyName, string abstractTypeFullyQualifiedName, string through = "") - => FeaturesResources.Implement_abstract_class + ";" + assemblyName + ";" + abstractTypeFullyQualifiedName + ";" + through; + => AnalyzersResources.Implement_abstract_class + ";" + assemblyName + ";" + abstractTypeFullyQualifiedName + ";" + through; } diff --git a/src/Features/Core/Portable/ImplementAbstractClass/ImplementAbstractClassData.cs b/src/Analyzers/Core/CodeFixes/ImplementAbstractClass/ImplementAbstractClassData.cs similarity index 94% rename from src/Features/Core/Portable/ImplementAbstractClass/ImplementAbstractClassData.cs rename to src/Analyzers/Core/CodeFixes/ImplementAbstractClass/ImplementAbstractClassData.cs index 6b43c78079bc4..f10fd4b026a4e 100644 --- a/src/Features/Core/Portable/ImplementAbstractClass/ImplementAbstractClassData.cs +++ b/src/Analyzers/Core/CodeFixes/ImplementAbstractClass/ImplementAbstractClassData.cs @@ -21,6 +21,12 @@ using Microsoft.CodeAnalysis.Shared.Utilities; using Roslyn.Utilities; +#if CODE_STYLE +using DeclarationModifiers = Microsoft.CodeAnalysis.Internal.Editing.DeclarationModifiers; +#else +using DeclarationModifiers = Microsoft.CodeAnalysis.Editing.DeclarationModifiers; +#endif + namespace Microsoft.CodeAnalysis.ImplementAbstractClass; internal sealed class ImplementAbstractClassData( @@ -51,7 +57,8 @@ internal sealed class ImplementAbstractClassData( if (abstractClassType == null || !abstractClassType.IsAbstractClass()) return null; - if (!CodeGenerator.CanAdd(document.Project.Solution, classType, cancellationToken)) + var generator = document.GetRequiredLanguageService(); + if (!generator.CanAddTo(classType, document.Project.Solution, cancellationToken)) return null; var unimplementedMembers = classType.GetAllUnimplementedMembers( @@ -95,7 +102,7 @@ public async Task ImplementAbstractClassAsync( classNodeToAddMembersTo = _classNode.ReplaceToken( _classIdentifier, _classIdentifier.WithAdditionalAnnotations(ConflictAnnotation.Create( - FeaturesResources.Base_classes_contain_inaccessible_unimplemented_members))); + AnalyzersResources.Base_classes_contain_inaccessible_unimplemented_members))); } var context = new CodeGenerationContext( @@ -172,7 +179,7 @@ private ISymbol GenerateMethod( DeclarationModifiers modifiers, Accessibility accessibility) { var syntaxFacts = _document.GetRequiredLanguageService(); - var generator = _document.GetRequiredLanguageService(); + var generator = SyntaxGenerator.GetGenerator(_document); var body = throughMember == null ? generator.CreateThrowNotImplementedStatement(compilation) : generator.GenerateDelegateThroughMemberStatement(method, throughMember); @@ -200,7 +207,7 @@ private IPropertySymbol GenerateProperty( propertyGenerationBehavior = ImplementTypePropertyGenerationBehavior.PreferThrowingProperties; } - var generator = _document.GetRequiredLanguageService(); + var generator = _document.GetRequiredLanguageService(); var preferAutoProperties = propertyGenerationBehavior == ImplementTypePropertyGenerationBehavior.PreferAutoProperties; var getMethod = ShouldGenerateAccessor(property.GetMethod) @@ -232,7 +239,7 @@ private IPropertySymbol GenerateProperty( private IEventSymbol GenerateEvent( IEventSymbol @event, ISymbol? throughMember, Accessibility accessibility, DeclarationModifiers modifiers) { - var generator = _document.GetRequiredLanguageService(); + var generator = _document.GetRequiredLanguageService(); return CodeGenerationSymbolFactory.CreateEventSymbol( @event, accessibility: accessibility, modifiers: modifiers, addMethod: GetEventAddOrRemoveMethod(@event, @event.AddMethod, throughMember, generator.AddEventHandler), @@ -246,7 +253,7 @@ private IEventSymbol GenerateEvent( if (accessor == null || throughMember == null) return null; - var generator = _document.GetRequiredLanguageService(); + var generator = _document.GetRequiredLanguageService(); var throughExpression = generator.CreateDelegateThroughExpression(@event, throughMember); var statement = generator.ExpressionStatement(createAddOrRemoveHandler( generator.MemberAccessExpression(throughExpression, @event.Name), diff --git a/src/Analyzers/Core/CodeFixes/ImplementInterface/IImplementInterfaceInfo.cs b/src/Analyzers/Core/CodeFixes/ImplementInterface/IImplementInterfaceInfo.cs new file mode 100644 index 0000000000000..707472fa1a64b --- /dev/null +++ b/src/Analyzers/Core/CodeFixes/ImplementInterface/IImplementInterfaceInfo.cs @@ -0,0 +1,34 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Immutable; + +namespace Microsoft.CodeAnalysis.ImplementInterface; + +internal interface IImplementInterfaceInfo +{ + /// + /// The class or struct that is implementing the interface. + /// + INamedTypeSymbol ClassOrStructType { get; } + + /// + /// The specific declaration node for that the interface implementations should be + /// added to. + /// + SyntaxNode ClassOrStructDecl { get; } + + SyntaxNode InterfaceNode { get; } + + /// + /// Set of interfaces to implement. Normally a single interface (when a user invokes the code action on a single + /// entry in the interface-list for a type). However, it may be multiple in the VB case where a user presses + /// 'enter' at the end of the interfaces list, where we'll implement all the missing members for all listed interfaces. + /// + ImmutableArray InterfaceTypes { get; } + + ImmutableArray<(INamedTypeSymbol type, ImmutableArray members)> MembersWithoutExplicitOrImplicitImplementationWhichCanBeImplicitlyImplemented { get; } + ImmutableArray<(INamedTypeSymbol type, ImmutableArray members)> MembersWithoutExplicitOrImplicitImplementation { get; } + ImmutableArray<(INamedTypeSymbol type, ImmutableArray members)> MembersWithoutExplicitImplementation { get; } +} diff --git a/src/Features/Core/Portable/ImplementInterface/ImplementHelpers.cs b/src/Analyzers/Core/CodeFixes/ImplementInterface/ImplementHelpers.cs similarity index 100% rename from src/Features/Core/Portable/ImplementInterface/ImplementHelpers.cs rename to src/Analyzers/Core/CodeFixes/ImplementInterface/ImplementHelpers.cs diff --git a/src/Features/Core/Portable/ImplementType/ImplementTypeInsertionBehavior.cs b/src/Analyzers/Core/CodeFixes/ImplementType/ImplementTypeInsertionBehavior.cs similarity index 100% rename from src/Features/Core/Portable/ImplementType/ImplementTypeInsertionBehavior.cs rename to src/Analyzers/Core/CodeFixes/ImplementType/ImplementTypeInsertionBehavior.cs diff --git a/src/Features/Core/Portable/ImplementType/ImplementTypeOptions.cs b/src/Analyzers/Core/CodeFixes/ImplementType/ImplementTypeOptions.cs similarity index 98% rename from src/Features/Core/Portable/ImplementType/ImplementTypeOptions.cs rename to src/Analyzers/Core/CodeFixes/ImplementType/ImplementTypeOptions.cs index c4d01765cdfde..035ecd08f73a8 100644 --- a/src/Features/Core/Portable/ImplementType/ImplementTypeOptions.cs +++ b/src/Analyzers/Core/CodeFixes/ImplementType/ImplementTypeOptions.cs @@ -2,14 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Immutable; -using System.Diagnostics; using System.Runtime.Serialization; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Options; -using Roslyn.Utilities; +using Microsoft.CodeAnalysis.Shared.Extensions; namespace Microsoft.CodeAnalysis.ImplementType; diff --git a/src/Features/Core/Portable/ImplementType/ImplementTypePropertyGenerationBehavior.cs b/src/Analyzers/Core/CodeFixes/ImplementType/ImplementTypePropertyGenerationBehavior.cs similarity index 100% rename from src/Features/Core/Portable/ImplementType/ImplementTypePropertyGenerationBehavior.cs rename to src/Analyzers/Core/CodeFixes/ImplementType/ImplementTypePropertyGenerationBehavior.cs diff --git a/src/Features/VisualBasic/Portable/ImplementAbstractClass/VisualBasicImplementAbstractClassCodeFixProvider.vb b/src/Analyzers/VisualBasic/CodeFixes/ImplementAbstractClass/VisualBasicImplementAbstractClassCodeFixProvider.vb similarity index 100% rename from src/Features/VisualBasic/Portable/ImplementAbstractClass/VisualBasicImplementAbstractClassCodeFixProvider.vb rename to src/Analyzers/VisualBasic/CodeFixes/ImplementAbstractClass/VisualBasicImplementAbstractClassCodeFixProvider.vb diff --git a/src/Analyzers/VisualBasic/CodeFixes/VisualBasicCodeFixes.projitems b/src/Analyzers/VisualBasic/CodeFixes/VisualBasicCodeFixes.projitems index 77ef8bc4ae0cd..a00da450b82a9 100644 --- a/src/Analyzers/VisualBasic/CodeFixes/VisualBasicCodeFixes.projitems +++ b/src/Analyzers/VisualBasic/CodeFixes/VisualBasicCodeFixes.projitems @@ -28,6 +28,7 @@ + diff --git a/src/Features/VisualBasicTest/ImplementAbstractClass/ImplementAbstractClassTests.vb b/src/Analyzers/VisualBasic/Tests/ImplementAbstractClass/ImplementAbstractClassTests.vb similarity index 100% rename from src/Features/VisualBasicTest/ImplementAbstractClass/ImplementAbstractClassTests.vb rename to src/Analyzers/VisualBasic/Tests/ImplementAbstractClass/ImplementAbstractClassTests.vb diff --git a/src/Features/VisualBasicTest/ImplementAbstractClass/ImplementAbstractClassTests_FixAllTests.vb b/src/Analyzers/VisualBasic/Tests/ImplementAbstractClass/ImplementAbstractClassTests_FixAllTests.vb similarity index 100% rename from src/Features/VisualBasicTest/ImplementAbstractClass/ImplementAbstractClassTests_FixAllTests.vb rename to src/Analyzers/VisualBasic/Tests/ImplementAbstractClass/ImplementAbstractClassTests_FixAllTests.vb diff --git a/src/Analyzers/VisualBasic/Tests/VisualBasicAnalyzers.UnitTests.projitems b/src/Analyzers/VisualBasic/Tests/VisualBasicAnalyzers.UnitTests.projitems index 9073e0997b3c4..f054840c1269d 100644 --- a/src/Analyzers/VisualBasic/Tests/VisualBasicAnalyzers.UnitTests.projitems +++ b/src/Analyzers/VisualBasic/Tests/VisualBasicAnalyzers.UnitTests.projitems @@ -23,6 +23,8 @@ + + diff --git a/src/Features/Core/Portable/Completion/Providers/AbstractPartialMethodCompletionProvider.cs b/src/Features/Core/Portable/Completion/Providers/AbstractPartialMethodCompletionProvider.cs index ddf3d0b4c1397..fbbdb17690df8 100644 --- a/src/Features/Core/Portable/Completion/Providers/AbstractPartialMethodCompletionProvider.cs +++ b/src/Features/Core/Portable/Completion/Providers/AbstractPartialMethodCompletionProvider.cs @@ -61,7 +61,7 @@ public override async Task ProvideCompletionsAsync(CompletionContext context) protected override async Task GenerateMemberAsync(ISymbol member, INamedTypeSymbol containingType, Document document, CompletionItem item, CancellationToken cancellationToken) { - var syntaxFactory = document.GetLanguageService(); + var syntaxFactory = document.GetRequiredLanguageService(); var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false); var method = (IMethodSymbol)member; diff --git a/src/Features/Core/Portable/FeaturesResources.resx b/src/Features/Core/Portable/FeaturesResources.resx index 2a56f3ef0c777..ac596d3038b58 100644 --- a/src/Features/Core/Portable/FeaturesResources.resx +++ b/src/Features/Core/Portable/FeaturesResources.resx @@ -914,9 +914,6 @@ This version used in: {2} (Unknown) - - Implement abstract class - Use framework type @@ -1322,18 +1319,12 @@ This version used in: {2} Value: - - Implement through '{0}' - Implement all interfaces explicitly Implement explicitly - - Base classes contain inaccessible unimplemented members - Add 'DebuggerDisplay' attribute {Locked="DebuggerDisplay"} "DebuggerDisplay" is a BCL class and should not be localized. @@ -3244,7 +3235,7 @@ Zero-width positive lookbehind assertions are typically used at the beginning of Query - Semantic search is only supported when code analysis runs in a separate process on the latest .NET (see Tools > Options > Text Editor > C# > Advanced). + Semantic search is only supported when code analysis runs in a separate process on the latest .NET (see Tools > Options > Text Editor > C# > Advanced). Semantic search query terminated with exception @@ -3264,9 +3255,6 @@ Zero-width positive lookbehind assertions are typically used at the beginning of Unable to load type '{0}': '{1}' - - Type members - .NET Code Actions diff --git a/src/Features/Core/Portable/GenerateDefaultConstructors/AbstractGenerateDefaultConstructorsService.AbstractCodeAction.cs b/src/Features/Core/Portable/GenerateDefaultConstructors/AbstractGenerateDefaultConstructorsService.AbstractCodeAction.cs index a130506638d6d..1a4524f83c378 100644 --- a/src/Features/Core/Portable/GenerateDefaultConstructors/AbstractGenerateDefaultConstructorsService.AbstractCodeAction.cs +++ b/src/Features/Core/Portable/GenerateDefaultConstructors/AbstractGenerateDefaultConstructorsService.AbstractCodeAction.cs @@ -54,7 +54,7 @@ protected override async Task GetChangedDocumentAsync(CancellationToke private IMethodSymbol CreateConstructorDefinition( IMethodSymbol baseConstructor) { - var syntaxFactory = _document.GetLanguageService(); + var syntaxFactory = _document.GetRequiredLanguageService(); var baseConstructorArguments = baseConstructor.Parameters.Length != 0 ? syntaxFactory.CreateArguments(baseConstructor.Parameters) : default; diff --git a/src/Features/Core/Portable/GenerateMember/GenerateConstructor/AbstractGenerateConstructorService.State.cs b/src/Features/Core/Portable/GenerateMember/GenerateConstructor/AbstractGenerateConstructorService.State.cs index 0f8c62b9c2bba..e5d5c77cc4a82 100644 --- a/src/Features/Core/Portable/GenerateMember/GenerateConstructor/AbstractGenerateConstructorService.State.cs +++ b/src/Features/Core/Portable/GenerateMember/GenerateConstructor/AbstractGenerateConstructorService.State.cs @@ -577,7 +577,7 @@ public async Task GetChangedDocumentAsync( var provider = document.Project.Solution.Services.GetLanguageServices(TypeToGenerateIn.Language); var (members, assignments) = await GenerateMembersAndAssignmentsAsync(document, withFields, withProperties, cancellationToken).ConfigureAwait(false); var isThis = _delegatedConstructor.ContainingType.OriginalDefinition.Equals(TypeToGenerateIn.OriginalDefinition); - var delegatingArguments = provider.GetService().CreateArguments(_delegatedConstructor.Parameters); + var delegatingArguments = provider.GetRequiredService().CreateArguments(_delegatedConstructor.Parameters); var newParameters = _delegatedConstructor.Parameters.Concat(_parameters); var generateUnsafe = !IsContainedInUnsafeType && newParameters.Any(static p => p.RequiresUnsafeModifier()); diff --git a/src/Features/Core/Portable/ImplementInterface/IImplementInterfaceService.cs b/src/Features/Core/Portable/ImplementInterface/IImplementInterfaceService.cs index 6fa7dd0e92187..e1403cb83fa29 100644 --- a/src/Features/Core/Portable/ImplementInterface/IImplementInterfaceService.cs +++ b/src/Features/Core/Portable/ImplementInterface/IImplementInterfaceService.cs @@ -10,33 +10,6 @@ namespace Microsoft.CodeAnalysis.ImplementInterface; -internal interface IImplementInterfaceInfo -{ - /// - /// The class or struct that is implementing the interface. - /// - INamedTypeSymbol ClassOrStructType { get; } - - /// - /// The specific declaration node for that the interface implementations should be - /// added to. - /// - SyntaxNode ClassOrStructDecl { get; } - - SyntaxNode InterfaceNode { get; } - - /// - /// Set of interfaces to implement. Normally a single interface (when a user invokes the code action on a single - /// entry in the interface-list for a type). However, it may be multiple in the VB case where a user presses - /// 'enter' at the end of the interfaces list, where we'll implement all the missing members for all listed interfaces. - /// - ImmutableArray InterfaceTypes { get; } - - ImmutableArray<(INamedTypeSymbol type, ImmutableArray members)> MembersWithoutExplicitOrImplicitImplementationWhichCanBeImplicitlyImplemented { get; } - ImmutableArray<(INamedTypeSymbol type, ImmutableArray members)> MembersWithoutExplicitOrImplicitImplementation { get; } - ImmutableArray<(INamedTypeSymbol type, ImmutableArray members)> MembersWithoutExplicitImplementation { get; } -} - internal readonly record struct ImplementInterfaceConfiguration { public bool ImplementDisposePattern { get; init; } diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.cs.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.cs.xlf index 8de55574a34a4..0974c048d694a 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.cs.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.cs.xlf @@ -315,11 +315,6 @@ Ujistěte se, že specifikátor tt použijete pro jazyky, pro které je nezbytn Očekávaná úloha nevrací žádnou hodnotu. - - Base classes contain inaccessible unimplemented members - Základní třídy obsahují nepřístupné nenaimplementované členy. - - Built-in Copilot analysis Integrovaná analýza Copilot @@ -935,11 +930,6 @@ Ujistěte se, že specifikátor tt použijete pro jazyky, pro které je nezbytn Implementovat rozhraní {0} implicitně - - Implement abstract class - Implementovat abstraktní třídu - - Implement all interfaces explicitly Implementovat všechna rozhraní explicitně @@ -970,11 +960,6 @@ Ujistěte se, že specifikátor tt použijete pro jazyky, pro které je nezbytn Implementovat zbývající členy explicitně - - Implement through '{0}' - Implementovat přes {0} - - Incomplete \p{X} character escape Neúplné uvození znaků \p{X} @@ -2815,11 +2800,6 @@ Pozitivní kontrolní výrazy zpětného vyhledávání s nulovou délkou se obv Čárka na konci není povolená - - Type members - Type members - - Types: Typy: diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.de.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.de.xlf index 0134ce9b7884e..f3c4fd2c1aea0 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.de.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.de.xlf @@ -315,11 +315,6 @@ Stellen Sie sicher, dass Sie den Bezeichner "tt" für Sprachen verwenden, für d Erwartete Aufgabe gibt keinen Wert zurück - - Base classes contain inaccessible unimplemented members - Basisklassen enthalten nicht implementierte Member, auf die nicht zugegriffen werden kann. - - Built-in Copilot analysis Integrierte Copilot-Analyse @@ -935,11 +930,6 @@ Stellen Sie sicher, dass Sie den Bezeichner "tt" für Sprachen verwenden, für d "{0}" implizit implementieren - - Implement abstract class - Abstrakte Klasse implementieren - - Implement all interfaces explicitly Alle Schnittstellen explizit implementieren @@ -970,11 +960,6 @@ Stellen Sie sicher, dass Sie den Bezeichner "tt" für Sprachen verwenden, für d Verbleibende Member explizit implementieren - - Implement through '{0}' - Über "{0}" implementieren - - Incomplete \p{X} character escape Unvollständiges \p{X}-Escapezeichen. @@ -2815,11 +2800,6 @@ Positive Lookbehindassertionen mit Nullbreite werden normalerweise am Anfang reg Ein nachgestelltes Komma ist unzulässig - - Type members - Type members - - Types: Typen: diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.es.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.es.xlf index 12763b22e7fac..87b89b43fd556 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.es.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.es.xlf @@ -315,11 +315,6 @@ Asegúrese de usar el especificador "tt" para los idiomas para los que es necesa La tarea esperada no devuelve ningún valor. - - Base classes contain inaccessible unimplemented members - Las clases base contienen miembros no implementados que son inaccesibles. - - Built-in Copilot analysis Análisis integrado de Copilot @@ -935,11 +930,6 @@ Asegúrese de usar el especificador "tt" para los idiomas para los que es necesa Implementar "{0}" de forma implícita - - Implement abstract class - Implementar clase abstracta - - Implement all interfaces explicitly Implementar todas las interfaces de forma explícita @@ -970,11 +960,6 @@ Asegúrese de usar el especificador "tt" para los idiomas para los que es necesa Implementar los miembros restantes de forma explícita - - Implement through '{0}' - Implementar a través de "{0}" - - Incomplete \p{X} character escape Escape de carácter incompleto \p{X} @@ -2815,11 +2800,6 @@ Las aserciones de búsqueda retrasada (lookbehind) positivas de ancho cero se us Coma final no permitida - - Type members - Type members - - Types: Tipos: diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.fr.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.fr.xlf index 493dab8aadc7e..29afab75954cd 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.fr.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.fr.xlf @@ -315,11 +315,6 @@ Veillez à utiliser le spécificateur "tt" pour les langues où il est nécessai La tâche attendue ne retourne aucune valeur - - Base classes contain inaccessible unimplemented members - Les classes de base contiennent des membres non implémentés inaccessibles - - Built-in Copilot analysis Analyse Copilot intégrée @@ -935,11 +930,6 @@ Veillez à utiliser le spécificateur "tt" pour les langues où il est nécessai Implémenter '{0}' implicitement - - Implement abstract class - Implémenter une classe abstraite - - Implement all interfaces explicitly Implémenter toutes les interfaces explicitement @@ -970,11 +960,6 @@ Veillez à utiliser le spécificateur "tt" pour les langues où il est nécessai Implémenter les membres restants explicitement - - Implement through '{0}' - Implémenter via '{0}' - - Incomplete \p{X} character escape Caractère d'échappement \p{X} incomplet @@ -2815,11 +2800,6 @@ Les assertions arrière positives de largeur nulle sont généralement utilisée Virgule de fin non autorisée - - Type members - Type members - - Types: Types : diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.it.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.it.xlf index 8dc9d8ee14cde..e99c476508d57 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.it.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.it.xlf @@ -315,11 +315,6 @@ Assicurarsi di usare l'identificatore "tt" per le lingue per le quali è necessa L'attività attesa non restituisce alcun valore - - Base classes contain inaccessible unimplemented members - Le classi di base contengono membri non implementati inaccessibili - - Built-in Copilot analysis Analisi Copilot predefinita @@ -935,11 +930,6 @@ Assicurarsi di usare l'identificatore "tt" per le lingue per le quali è necessa Implementa '{0}' in modo implicito - - Implement abstract class - Implementa la classe astratta - - Implement all interfaces explicitly Implementa tutte le interfacce in modo esplicito @@ -970,11 +960,6 @@ Assicurarsi di usare l'identificatore "tt" per le lingue per le quali è necessa Implementare i membri rimanenti in modo esplicito - - Implement through '{0}' - Implementa tramite '{0}' - - Incomplete \p{X} character escape Sequenza di caratteri di escape \p{X} incompleta @@ -2815,11 +2800,6 @@ Le asserzioni lookbehind positive di larghezza zero vengono usate in genere all' Virgola finale non consentita - - Type members - Type members - - Types: Tipi: diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.ja.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.ja.xlf index 419e7002402cd..224868646511e 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.ja.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.ja.xlf @@ -315,11 +315,6 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma 待機中のタスクは値を返しません - - Base classes contain inaccessible unimplemented members - アクセス不可能な未実装のメンバーが基底クラスに含まれています - - Built-in Copilot analysis 組み込みの Copilot の分析 @@ -935,11 +930,6 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma '{0}' を暗黙的に実装する - - Implement abstract class - 抽象クラスの実装 - - Implement all interfaces explicitly すべてのインターフェイスを明示的に実装する @@ -970,11 +960,6 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma 残りのメンバーを明示的に実装する - - Implement through '{0}' - '{0}' を通じて実装します - - Incomplete \p{X} character escape 不完全な \p{X} 文字エスケープです @@ -2815,11 +2800,6 @@ Zero-width positive lookbehind assertions are typically used at the beginning of 末尾にコンマは使用できない - - Type members - Type members - - Types: 型: diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.ko.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.ko.xlf index 2dfaf29cfbb79..7737c9873da41 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.ko.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.ko.xlf @@ -315,11 +315,6 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma 대기된 작업에서 값이 반환되지 않음 - - Base classes contain inaccessible unimplemented members - 기본 클래스에 구현되지 않아 액세스할 수 없는 멤버가 포함되어 있습니다. - - Built-in Copilot analysis 기본 제공 Copilot 분석 @@ -935,11 +930,6 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma '{0}'을(를) 암시적으로 구현 - - Implement abstract class - 추상 클래스 구현 - - Implement all interfaces explicitly 모든 인터페이스를 명시적으로 구현 @@ -970,11 +960,6 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma 나머지 멤버를 명시적으로 구현 - - Implement through '{0}' - '{0}'을(를) 통해 구현 - - Incomplete \p{X} character escape 불완전한 \p{X} 문자 이스케이프 @@ -2815,11 +2800,6 @@ Zero-width positive lookbehind assertions are typically used at the beginning of 후행 쉼표는 허용되지 않습니다. - - Type members - Type members - - Types: 형식: diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.pl.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.pl.xlf index c4079c2570689..2316346a94bfa 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.pl.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.pl.xlf @@ -315,11 +315,6 @@ Pamiętaj, aby nie używać specyfikatora „tt” dla wszystkich języków, w k Zadanie, na które oczekiwano, nie zwraca wartości - - Base classes contain inaccessible unimplemented members - Klasy podstawowe zawierają niedostępne niezaimplementowane składowe - - Built-in Copilot analysis Wbudowana analiza funkcji Copilot @@ -935,11 +930,6 @@ Pamiętaj, aby nie używać specyfikatora „tt” dla wszystkich języków, w k Niejawnie zaimplementuj interfejs „{0}” - - Implement abstract class - Implementuj klasę abstrakcyjną - - Implement all interfaces explicitly Jawnie zaimplementuj wszystkie interfejsy @@ -970,11 +960,6 @@ Pamiętaj, aby nie używać specyfikatora „tt” dla wszystkich języków, w k Jawnie zaimplementuj pozostałe składowe - - Implement through '{0}' - Implementuj za pomocą elementu „{0}” - - Incomplete \p{X} character escape Niekompletna sekwencja ucieczki znaku \p{X} @@ -2815,11 +2800,6 @@ Pozytywne asercje wsteczne o zerowej szerokości są zwykle używane na początk Końcowy przecinek jest niedozwolony. - - Type members - Type members - - Types: Typy: diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.pt-BR.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.pt-BR.xlf index b092679b8ac85..02e03348d5e08 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.pt-BR.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.pt-BR.xlf @@ -315,11 +315,6 @@ Verifique se o especificador "tt" foi usado para idiomas para os quais é necess A tarefa esperada não retorna nenhum valor - - Base classes contain inaccessible unimplemented members - As classes base contêm membros não implementados inacessíveis - - Built-in Copilot analysis Análise interna do Copilot @@ -935,11 +930,6 @@ Verifique se o especificador "tt" foi usado para idiomas para os quais é necess Implementar '{0}' implicitamente - - Implement abstract class - Implementar classe abstrata - - Implement all interfaces explicitly Implementar todas as interfaces explicitamente @@ -970,11 +960,6 @@ Verifique se o especificador "tt" foi usado para idiomas para os quais é necess Implementar os membros restantes explicitamente - - Implement through '{0}' - Implementar por meio de '{0}' - - Incomplete \p{X} character escape Escape de caractere incompleto \p{X} @@ -2815,11 +2800,6 @@ As declarações de lookbehind positivas de largura zero normalmente são usadas Vírgula à direita não permitida - - Type members - Type members - - Types: Tipos: diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.ru.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.ru.xlf index 1dbe5acb553b3..26dbf4d3373ef 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.ru.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.ru.xlf @@ -315,11 +315,6 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma Ожидаемая задача не возвращает значение. - - Base classes contain inaccessible unimplemented members - Базовые классы содержат недоступные нереализованные члены - - Built-in Copilot analysis Встроенный анализ Copilot @@ -935,11 +930,6 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma Реализовать "{0}" неявно - - Implement abstract class - Реализовать абстрактный класс - - Implement all interfaces explicitly Реализовать все интерфейсы явно @@ -970,11 +960,6 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma Реализовать оставшиеся элементы явно - - Implement through '{0}' - Реализовать через "{0}" - - Incomplete \p{X} character escape Незавершенная escape-последовательность \p{X} @@ -2815,11 +2800,6 @@ Zero-width positive lookbehind assertions are typically used at the beginning of Завершающая запятая не разрешена - - Type members - Type members - - Types: Типы: diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.tr.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.tr.xlf index ffd2f5a6894e9..41115c17fe9f4 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.tr.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.tr.xlf @@ -315,11 +315,6 @@ AM ve PM arasındaki farkın korunmasının gerekli olduğu diller için "tt" be Beklenen görev değer döndürmüyor - - Base classes contain inaccessible unimplemented members - Temel sınıflarda erişilemeyen, uygulanmamış üyeler var - - Built-in Copilot analysis Yerleşik Copilot analizi @@ -935,11 +930,6 @@ AM ve PM arasındaki farkın korunmasının gerekli olduğu diller için "tt" be '{0}' öğesini örtük olarak uygula - - Implement abstract class - Soyut sınıfı uygula - - Implement all interfaces explicitly Tüm arabirimleri açıkça uygula @@ -970,11 +960,6 @@ AM ve PM arasındaki farkın korunmasının gerekli olduğu diller için "tt" be Kalan üyeleri açıkça uygula - - Implement through '{0}' - '{0}' aracılığıyla uygula - - Incomplete \p{X} character escape Tamamlanmamış \p{X} karakter kaçış @@ -2815,11 +2800,6 @@ Sıfır genişlikli pozitif geri yönlü onaylamalar genellikle normal ifadeleri Sona eklenen virgüle izin verilmiyor - - Type members - Type members - - Types: Türler: diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hans.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hans.xlf index 0b454746e0186..42f12eca46fd4 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hans.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hans.xlf @@ -315,11 +315,6 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma 等待任务没有返回任何值 - - Base classes contain inaccessible unimplemented members - 基类包含无法访问的未实现成员 - - Built-in Copilot analysis 内置 Copilot 分析 @@ -935,11 +930,6 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma 隐式实现 "{0}" - - Implement abstract class - 实现抽象类 - - Implement all interfaces explicitly 显式实现所有接口 @@ -970,11 +960,6 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma 显式实现剩余成员 - - Implement through '{0}' - 通过“{0}”实现 - - Incomplete \p{X} character escape \p{X} 字符转义不完整 @@ -2815,11 +2800,6 @@ Zero-width positive lookbehind assertions are typically used at the beginning of 不允许使用尾随逗号 - - Type members - Type members - - Types: 类型: diff --git a/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hant.xlf b/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hant.xlf index 74a134341b268..1a384fa52df8b 100644 --- a/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hant.xlf +++ b/src/Features/Core/Portable/xlf/FeaturesResources.zh-Hant.xlf @@ -315,11 +315,6 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma 等待的工作不會傳回任何值 - - Base classes contain inaccessible unimplemented members - 基底類別包含無法存取的未實作成員 - - Built-in Copilot analysis 內建 Copilot 分析 @@ -935,11 +930,6 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma 隱含實作 '{0}' - - Implement abstract class - 實作抽象類別 - - Implement all interfaces explicitly 明確實作所有介面 @@ -970,11 +960,6 @@ Make sure to use the "tt" specifier for languages for which it's necessary to ma 明確實作剩餘的成員 - - Implement through '{0}' - 透過 '{0}' 實作 - - Incomplete \p{X} character escape 不完整的 \p{X} 字元逸出 @@ -2815,11 +2800,6 @@ Zero-width positive lookbehind assertions are typically used at the beginning of 尾端不得為逗號 - - Type members - Type members - - Types: 類型: diff --git a/src/Workspaces/Core/Portable/Shared/Extensions/IMethodSymbolExtensions.cs b/src/Workspaces/Core/Portable/Shared/Extensions/IMethodSymbolExtensions.cs index e947f678c5399..b23036ed0d967 100644 --- a/src/Workspaces/Core/Portable/Shared/Extensions/IMethodSymbolExtensions.cs +++ b/src/Workspaces/Core/Portable/Shared/Extensions/IMethodSymbolExtensions.cs @@ -54,129 +54,6 @@ public static bool CompatibleSignatureToDelegate(this IMethodSymbol method, INam return true; } - public static IMethodSymbol RenameTypeParameters(this IMethodSymbol method, ImmutableArray newNames) - { - if (method.TypeParameters.Select(t => t.Name).SequenceEqual(newNames)) - { - return method; - } - - var typeGenerator = new TypeGenerator(); - var updatedTypeParameters = RenameTypeParameters( - method.TypeParameters, newNames, typeGenerator); - - var mapping = new Dictionary(SymbolEqualityComparer.Default); - for (var i = 0; i < method.TypeParameters.Length; i++) - { - mapping[method.TypeParameters[i]] = updatedTypeParameters[i]; - } - - return CodeGenerationSymbolFactory.CreateMethodSymbol( - method.ContainingType, - method.GetAttributes(), - method.DeclaredAccessibility, - method.GetSymbolModifiers(), - method.ReturnType.SubstituteTypes(mapping, typeGenerator), - method.RefKind, - method.ExplicitInterfaceImplementations, - method.Name, - updatedTypeParameters, - method.Parameters.SelectAsArray(p => - CodeGenerationSymbolFactory.CreateParameterSymbol(p.GetAttributes(), p.RefKind, p.IsParams, p.Type.SubstituteTypes(mapping, typeGenerator), p.Name, p.IsOptional, - p.HasExplicitDefaultValue, p.HasExplicitDefaultValue ? p.ExplicitDefaultValue : null))); - } - - public static IMethodSymbol RenameParameters( - this IMethodSymbol method, ImmutableArray parameterNames) - { - var parameterList = method.Parameters; - if (parameterList.Select(p => p.Name).SequenceEqual(parameterNames)) - { - return method; - } - - var parameters = parameterList.RenameParameters(parameterNames); - - return CodeGenerationSymbolFactory.CreateMethodSymbol( - method.ContainingType, - method.GetAttributes(), - method.DeclaredAccessibility, - method.GetSymbolModifiers(), - method.ReturnType, - method.RefKind, - method.ExplicitInterfaceImplementations, - method.Name, - method.TypeParameters, - parameters); - } - - private static ImmutableArray RenameTypeParameters( - ImmutableArray typeParameters, - ImmutableArray newNames, - ITypeGenerator typeGenerator) - { - // We generate the type parameter in two passes. The first creates the new type - // parameter. The second updates the constraints to point at this new type parameter. - var newTypeParameters = new List(); - - var mapping = new Dictionary(SymbolEqualityComparer.Default); - for (var i = 0; i < typeParameters.Length; i++) - { - var typeParameter = typeParameters[i]; - - var newTypeParameter = new CodeGenerationTypeParameterSymbol( - typeParameter.ContainingType, - typeParameter.GetAttributes(), - typeParameter.Variance, - newNames[i], - typeParameter.NullableAnnotation, - typeParameter.ConstraintTypes, - typeParameter.HasConstructorConstraint, - typeParameter.HasReferenceTypeConstraint, - typeParameter.HasValueTypeConstraint, - typeParameter.HasUnmanagedTypeConstraint, - typeParameter.HasNotNullConstraint, - typeParameter.AllowsRefLikeType, - typeParameter.Ordinal); - - newTypeParameters.Add(newTypeParameter); - mapping[typeParameter] = newTypeParameter; - } - - // Now we update the constraints. - foreach (var newTypeParameter in newTypeParameters) - { - newTypeParameter.ConstraintTypes = ImmutableArray.CreateRange(newTypeParameter.ConstraintTypes, t => t.SubstituteTypes(mapping, typeGenerator)); - } - - return newTypeParameters.Cast().ToImmutableArray(); - } - - public static IMethodSymbol EnsureNonConflictingNames( - this IMethodSymbol method, INamedTypeSymbol containingType, ISyntaxFactsService syntaxFacts) - { - // The method's type parameters may conflict with the type parameters in the type - // we're generating into. In that case, rename them. - var parameterNames = NameGenerator.EnsureUniqueness( - method.Parameters.SelectAsArray(p => p.Name), isCaseSensitive: syntaxFacts.IsCaseSensitive); - - var outerTypeParameterNames = - containingType.GetAllTypeParameters() - .Select(tp => tp.Name) - .Concat(method.Name) - .Concat(containingType.Name); - - var unusableNames = parameterNames.Concat(outerTypeParameterNames).ToSet( - syntaxFacts.IsCaseSensitive ? StringComparer.Ordinal : StringComparer.OrdinalIgnoreCase); - - var newTypeParameterNames = NameGenerator.EnsureUniqueness( - method.TypeParameters.SelectAsArray(tp => tp.Name), - n => !unusableNames.Contains(n)); - - var updatedMethod = method.RenameTypeParameters(newTypeParameterNames); - return updatedMethod.RenameParameters(parameterNames); - } - public static IMethodSymbol RemoveInaccessibleAttributesAndAttributesOfTypes( this IMethodSymbol method, ISymbol accessibleWithin, params INamedTypeSymbol[] removeAttributeTypes) diff --git a/src/Workspaces/Core/Portable/Shared/Extensions/IParameterSymbolExtensions.cs b/src/Workspaces/Core/Portable/Shared/Extensions/IParameterSymbolExtensions.cs index 431849b2f8c0a..d56f340cb57e2 100644 --- a/src/Workspaces/Core/Portable/Shared/Extensions/IParameterSymbolExtensions.cs +++ b/src/Workspaces/Core/Portable/Shared/Extensions/IParameterSymbolExtensions.cs @@ -10,21 +10,6 @@ namespace Microsoft.CodeAnalysis.Shared.Extensions; internal static partial class IParameterSymbolExtensions { - public static IParameterSymbol RenameParameter(this IParameterSymbol parameter, string parameterName) - { - return parameter.Name == parameterName - ? parameter - : CodeGenerationSymbolFactory.CreateParameterSymbol( - parameter.GetAttributes(), - parameter.RefKind, - parameter.IsParams, - parameter.Type, - parameterName, - parameter.IsOptional, - parameter.HasExplicitDefaultValue, - parameter.HasExplicitDefaultValue ? parameter.ExplicitDefaultValue : null); - } - public static IParameterSymbol WithAttributes(this IParameterSymbol parameter, ImmutableArray attributes) { return parameter.GetAttributes() == attributes @@ -39,13 +24,4 @@ public static IParameterSymbol WithAttributes(this IParameterSymbol parameter, I parameter.HasExplicitDefaultValue, parameter.HasExplicitDefaultValue ? parameter.ExplicitDefaultValue : null); } - - public static ImmutableArray RenameParameters(this IList parameters, ImmutableArray parameterNames) - { - var result = new FixedSizeArrayBuilder(parameters.Count); - for (var i = 0; i < parameterNames.Length; i++) - result.Add(parameters[i].RenameParameter(parameterNames[i])); - - return result.MoveToImmutable(); - } } diff --git a/src/Workspaces/Core/Portable/Shared/Extensions/ITypeSymbolExtensions.cs b/src/Workspaces/Core/Portable/Shared/Extensions/ITypeSymbolExtensions.cs index 81d5e4ae6b509..98201956fdba4 100644 --- a/src/Workspaces/Core/Portable/Shared/Extensions/ITypeSymbolExtensions.cs +++ b/src/Workspaces/Core/Portable/Shared/Extensions/ITypeSymbolExtensions.cs @@ -208,28 +208,6 @@ from member in baseType.GetMembers(constructedInterfaceMember.Name).OfType( - this ITypeSymbol? type, - IDictionary mapping, - Compilation compilation) - where TType1 : ITypeSymbol - where TType2 : ITypeSymbol - { - return type.SubstituteTypes(mapping, new CompilationTypeGenerator(compilation)); - } - - [return: NotNullIfNotNull(parameterName: nameof(type))] - public static ITypeSymbol? SubstituteTypes( - this ITypeSymbol? type, - IDictionary mapping, - ITypeGenerator typeGenerator) - where TType1 : ITypeSymbol - where TType2 : ITypeSymbol - { - return type?.Accept(new SubstituteTypesVisitor(mapping, typeGenerator)); - } - public static bool CanBeEnumerated(this ITypeSymbol type) { // Type itself is IEnumerable/IEnumerable diff --git a/src/Workspaces/Core/Portable/Shared/Extensions/SyntaxGeneratorExtensions.cs b/src/Workspaces/Core/Portable/Shared/Extensions/SyntaxGeneratorExtensions.cs index ecce1282f978b..89c44e9d4a0c0 100644 --- a/src/Workspaces/Core/Portable/Shared/Extensions/SyntaxGeneratorExtensions.cs +++ b/src/Workspaces/Core/Portable/Shared/Extensions/SyntaxGeneratorExtensions.cs @@ -321,7 +321,7 @@ public static async Task OverridePropertyAsync( // Implement an abstract property by throwing not implemented in accessors. if (overriddenProperty.IsAbstract) { - var compilation = await document.Project.GetCompilationAsync(cancellationToken).ConfigureAwait(false); + var compilation = await document.Project.GetRequiredCompilationAsync(cancellationToken).ConfigureAwait(false); var statement = codeFactory.CreateThrowNotImplementedStatement(compilation); getBody = statement; @@ -510,7 +510,7 @@ private static async Task OverrideMethodAsync( // Abstract: Throw not implemented if (overriddenMethod.IsAbstract) { - var compilation = await newDocument.Project.GetCompilationAsync(cancellationToken).ConfigureAwait(false); + var compilation = await newDocument.Project.GetRequiredCompilationAsync(cancellationToken).ConfigureAwait(false); var statement = codeFactory.CreateThrowNotImplementedStatement(compilation); return CodeGenerationSymbolFactory.CreateMethodSymbol( @@ -544,149 +544,4 @@ private static async Task OverrideMethodAsync( : [codeFactory.ReturnStatement(body)]); } } - - /// - /// Generates a call to a method *through* an existing field or property symbol. - /// - /// - public static SyntaxNode GenerateDelegateThroughMemberStatement( - this SyntaxGenerator generator, IMethodSymbol method, ISymbol throughMember) - { - var through = generator.MemberAccessExpression( - CreateDelegateThroughExpression(generator, method, throughMember), - method.IsGenericMethod - ? generator.GenericName(method.Name, method.TypeArguments) - : generator.IdentifierName(method.Name)); - - var invocationExpression = generator.InvocationExpression(through, generator.CreateArguments(method.Parameters)); - return method.ReturnsVoid - ? generator.ExpressionStatement(invocationExpression) - : generator.ReturnStatement(invocationExpression); - } - - public static SyntaxNode CreateDelegateThroughExpression( - this SyntaxGenerator generator, ISymbol member, ISymbol throughMember) - { - var name = generator.IdentifierName(throughMember.Name); - var through = throughMember.IsStatic - ? GenerateContainerName(generator, throughMember) - // If we're delegating through a primary constructor parameter, we cannot qualify the name at all. - : throughMember is IParameterSymbol - ? null - : generator.ThisExpression(); - - through = through is null ? name : generator.MemberAccessExpression(through, name); - - var throughMemberType = throughMember.GetMemberType(); - if (throughMemberType != null && - member.ContainingType is { TypeKind: TypeKind.Interface } interfaceBeingImplemented) - { - // In the case of 'implement interface through field / property', we need to know what - // interface we are implementing so that we can insert casts to this interface on every - // usage of the field in the generated code. Without these casts we would end up generating - // code that fails compilation in certain situations. - // - // For example consider the following code. - // class C : IReadOnlyList { int[] field; } - // When applying the 'implement interface through field' code fix in the above example, - // we need to generate the following code to implement the Count property on IReadOnlyList - // class C : IReadOnlyList { int[] field; int Count { get { ((IReadOnlyList)field).Count; } ...} - // as opposed to the following code which will fail to compile (because the array field - // doesn't have a property named .Count) - - // class C : IReadOnlyList { int[] field; int Count { get { field.Count; } ...} - // - // The 'InterfaceTypes' property on the state object always contains only one item - // in the case of C# i.e. it will contain exactly the interface we are trying to implement. - // This is also the case most of the time in the case of VB, except in certain error conditions - // (recursive / circular cases) where the span of the squiggle for the corresponding - // diagnostic (BC30149) changes and 'InterfaceTypes' ends up including all interfaces - // in the Implements clause. For the purposes of inserting the above cast, we ignore the - // uncommon case and optimize for the common one - in other words, we only apply the cast - // in cases where we can unambiguously figure out which interface we are trying to implement. - if (!throughMemberType.Equals(interfaceBeingImplemented)) - { - through = generator.CastExpression(interfaceBeingImplemented, - through.WithAdditionalAnnotations(Simplifier.Annotation)); - } - else if (throughMember is IPropertySymbol { IsStatic: false, ExplicitInterfaceImplementations: [var explicitlyImplementedProperty, ..] }) - { - // If we are implementing through an explicitly implemented property, we need to cast 'this' to - // the explicitly implemented interface type before calling the member, as in: - // ((IA)this).Prop.Member(); - // - var explicitImplementationCast = generator.CastExpression( - explicitlyImplementedProperty.ContainingType, - generator.ThisExpression()); - - through = generator.MemberAccessExpression(explicitImplementationCast, - generator.IdentifierName(explicitlyImplementedProperty.Name)); - - through = through.WithAdditionalAnnotations(Simplifier.Annotation); - } - } - - return through.WithAdditionalAnnotations(Simplifier.Annotation); - - // local functions - - static SyntaxNode GenerateContainerName(SyntaxGenerator factory, ISymbol throughMember) - { - var classOrStructType = throughMember.ContainingType; - return classOrStructType.IsGenericType - ? factory.GenericName(classOrStructType.Name, classOrStructType.TypeArguments) - : factory.IdentifierName(classOrStructType.Name); - } - } - - public static ImmutableArray GetGetAccessorStatements( - this SyntaxGenerator generator, Compilation compilation, - IPropertySymbol property, ISymbol? throughMember, bool preferAutoProperties) - { - if (throughMember != null) - { - var throughExpression = CreateDelegateThroughExpression(generator, property, throughMember); - var expression = property.IsIndexer - ? throughExpression - : generator.MemberAccessExpression( - throughExpression, generator.IdentifierName(property.Name)); - - if (property.Parameters.Length > 0) - { - var arguments = generator.CreateArguments(property.Parameters); - expression = generator.ElementAccessExpression(expression, arguments); - } - - return [generator.ReturnStatement(expression)]; - } - - return preferAutoProperties ? default : generator.CreateThrowNotImplementedStatementBlock(compilation); - } - - public static ImmutableArray GetSetAccessorStatements( - this SyntaxGenerator generator, Compilation compilation, - IPropertySymbol property, ISymbol? throughMember, bool preferAutoProperties) - { - if (throughMember != null) - { - var throughExpression = CreateDelegateThroughExpression(generator, property, throughMember); - var expression = property.IsIndexer - ? throughExpression - : generator.MemberAccessExpression( - throughExpression, generator.IdentifierName(property.Name)); - - if (property.Parameters.Length > 0) - { - var arguments = generator.CreateArguments(property.Parameters); - expression = generator.ElementAccessExpression(expression, arguments); - } - - expression = generator.AssignmentStatement(expression, generator.IdentifierName("value")); - - return [generator.ExpressionStatement(expression)]; - } - - return preferAutoProperties - ? default - : generator.CreateThrowNotImplementedStatementBlock(compilation); - } } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeCleanup/CodeCleanupOptions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeCleanup/CodeCleanupOptions.cs index d9faeb67b65c6..9edd5a1e66e0c 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeCleanup/CodeCleanupOptions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeCleanup/CodeCleanupOptions.cs @@ -43,24 +43,3 @@ public OrganizeImportsOptions GetOrganizeImportsOptions() }; #endif } - -internal static class CodeCleanupOptionsProviders -{ -#if !CODE_STYLE - public static CodeCleanupOptions GetCodeCleanupOptions(this IOptionsReader options, LanguageServices languageServices, bool? allowImportsInHiddenRegions = null) - => new() - { - FormattingOptions = options.GetSyntaxFormattingOptions(languageServices), - SimplifierOptions = options.GetSimplifierOptions(languageServices), - AddImportOptions = options.GetAddImportPlacementOptions(languageServices, allowImportsInHiddenRegions), - DocumentFormattingOptions = options.GetDocumentFormattingOptions(), - }; - - public static async ValueTask GetCodeCleanupOptionsAsync(this Document document, CancellationToken cancellationToken) - { - var configOptions = await document.GetAnalyzerConfigOptionsAsync(cancellationToken).ConfigureAwait(false); - return configOptions.GetCodeCleanupOptions(document.Project.Services, document.AllowImportsInHiddenRegions()); - } -#endif -} - diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CodeGenerationOptions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CodeGenerationOptions.cs index a0df454f12d47..b0738940b39aa 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CodeGenerationOptions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CodeGenerationOptions.cs @@ -63,40 +63,3 @@ internal static CodeAndImportGenerationOptions GetDefault(LanguageServices langu }; #endif } - -internal static class CodeGenerationOptionsProviders -{ -#if !CODE_STYLE - public static CodeGenerationOptions GetCodeGenerationOptions(this IOptionsReader options, LanguageServices languageServices) - => languageServices.GetRequiredService().GetCodeGenerationOptions(options); - - public static CodeAndImportGenerationOptions GetCodeAndImportGenerationOptions(this IOptionsReader options, LanguageServices languageServices, bool? allowImportsInHiddenRegions = null) - => new() - { - GenerationOptions = options.GetCodeGenerationOptions(languageServices), - AddImportOptions = options.GetAddImportPlacementOptions(languageServices, allowImportsInHiddenRegions) - }; - - public static CleanCodeGenerationOptions GetCleanCodeGenerationOptions(this IOptionsReader options, LanguageServices languageServices, bool? allowImportsInHiddenRegions = null) - => new() - { - GenerationOptions = options.GetCodeGenerationOptions(languageServices), - CleanupOptions = options.GetCodeCleanupOptions(languageServices, allowImportsInHiddenRegions) - }; - - public static async ValueTask GetCodeGenerationOptionsAsync(this Document document, CancellationToken cancellationToken) - { - var configOptions = await document.GetAnalyzerConfigOptionsAsync(cancellationToken).ConfigureAwait(false); - return configOptions.GetCodeGenerationOptions(document.Project.Services); - } - - public static async ValueTask GetCodeGenerationInfoAsync(this Document document, CodeGenerationContext context, CancellationToken cancellationToken) - { - Contract.ThrowIfNull(document.Project.ParseOptions); - - var options = await GetCodeGenerationOptionsAsync(document, cancellationToken).ConfigureAwait(false); - var service = document.Project.Services.GetRequiredService(); - return service.GetInfo(context, options, document.Project.ParseOptions); - } -#endif -} diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/IMethodSymbolExtensions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/IMethodSymbolExtensions.cs index 80f330f63f35f..87a272da45712 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/IMethodSymbolExtensions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/IMethodSymbolExtensions.cs @@ -8,6 +8,7 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; using Microsoft.CodeAnalysis.LanguageService; +using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.Shared.Extensions; diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CSharpWorkspaceExtensions.projitems b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CSharpWorkspaceExtensions.projitems index 3d1ed9d703fd6..0252cf009b8ee 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CSharpWorkspaceExtensions.projitems +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CSharpWorkspaceExtensions.projitems @@ -16,6 +16,7 @@ + diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/CSharpCodeGenerationService.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/CSharpCodeGenerationService.cs index e642587180e98..fcc39d5ffff17 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/CSharpCodeGenerationService.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/CSharpCodeGenerationService.cs @@ -25,13 +25,9 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeGeneration; using static CSharpSyntaxTokens; using static SyntaxFactory; -internal partial class CSharpCodeGenerationService : AbstractCodeGenerationService +internal sealed partial class CSharpCodeGenerationService(LanguageServices languageServices) + : AbstractCodeGenerationService(languageServices) { - public CSharpCodeGenerationService(LanguageServices languageServices) - : base(languageServices) - { - } - public override CodeGenerationOptions DefaultOptions => CSharpCodeGenerationOptions.Default; diff --git a/src/Workspaces/CSharp/Portable/CodeGeneration/CSharpCodeGenerationServiceFactory.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/CSharpCodeGenerationServiceFactory.cs similarity index 100% rename from src/Workspaces/CSharp/Portable/CodeGeneration/CSharpCodeGenerationServiceFactory.cs rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/CodeGeneration/CSharpCodeGenerationServiceFactory.cs diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/AddImport/AddImportPlacementOptionsProviders.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/AddImport/AddImportPlacementOptionsProviders.cs index 121804f0dfacd..c484c19d89c2e 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/AddImport/AddImportPlacementOptionsProviders.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/AddImport/AddImportPlacementOptionsProviders.cs @@ -21,10 +21,8 @@ public static bool AllowImportsInHiddenRegions(this Document document) => document.Services.GetService()?.SupportsMappingImportDirectives == true; #endif -#if !CODE_STYLE public static AddImportPlacementOptions GetAddImportPlacementOptions(this IOptionsReader options, Host.LanguageServices languageServices, bool? allowInHiddenRegions) => languageServices.GetRequiredService().GetAddImportOptions(options, allowInHiddenRegions ?? AddImportPlacementOptions.Default.AllowInHiddenRegions); -#endif public static async ValueTask GetAddImportPlacementOptionsAsync(this Document document, CancellationToken cancellationToken) { diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeCleanup/CodeCleanupOptionsProviders.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeCleanup/CodeCleanupOptionsProviders.cs new file mode 100644 index 0000000000000..396b813e9f95c --- /dev/null +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeCleanup/CodeCleanupOptionsProviders.cs @@ -0,0 +1,34 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Threading; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis.AddImport; +using Microsoft.CodeAnalysis.Formatting; +using Microsoft.CodeAnalysis.Host; +using Microsoft.CodeAnalysis.Options; +using Microsoft.CodeAnalysis.Simplification; + +namespace Microsoft.CodeAnalysis.CodeCleanup; + +internal static class CodeCleanupOptionsProviders +{ + public static CodeCleanupOptions GetCodeCleanupOptions(this IOptionsReader options, LanguageServices languageServices, bool? allowImportsInHiddenRegions = null) + => new() + { + FormattingOptions = options.GetSyntaxFormattingOptions(languageServices), + SimplifierOptions = options.GetSimplifierOptions(languageServices), + AddImportOptions = options.GetAddImportPlacementOptions(languageServices, allowImportsInHiddenRegions), + DocumentFormattingOptions = options.GetDocumentFormattingOptions(), + }; + +#if !CODE_STYLE + public static async ValueTask GetCodeCleanupOptionsAsync(this Document document, CancellationToken cancellationToken) + { + var configOptions = await document.GetAnalyzerConfigOptionsAsync(cancellationToken).ConfigureAwait(false); + return configOptions.GetCodeCleanupOptions(document.Project.Services, document.AllowImportsInHiddenRegions()); + } +#endif +} + diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationOptionsProvider.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationOptionsProvider.cs new file mode 100644 index 0000000000000..602a383f4e600 --- /dev/null +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/CodeGenerationOptionsProvider.cs @@ -0,0 +1,49 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Threading; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis.AddImport; +using Microsoft.CodeAnalysis.CodeCleanup; +using Microsoft.CodeAnalysis.Host; +using Microsoft.CodeAnalysis.Options; +using Microsoft.CodeAnalysis.Shared.Extensions; +using Roslyn.Utilities; + +namespace Microsoft.CodeAnalysis.CodeGeneration; + +internal static class CodeGenerationOptionsProviders +{ + public static CodeGenerationOptions GetCodeGenerationOptions(this IOptionsReader options, LanguageServices languageServices) + => languageServices.GetRequiredService().GetCodeGenerationOptions(options); + + public static CodeAndImportGenerationOptions GetCodeAndImportGenerationOptions(this IOptionsReader options, LanguageServices languageServices, bool? allowImportsInHiddenRegions = null) + => new() + { + GenerationOptions = options.GetCodeGenerationOptions(languageServices), + AddImportOptions = options.GetAddImportPlacementOptions(languageServices, allowImportsInHiddenRegions) + }; + + public static CleanCodeGenerationOptions GetCleanCodeGenerationOptions(this IOptionsReader options, LanguageServices languageServices, bool? allowImportsInHiddenRegions = null) + => new() + { + GenerationOptions = options.GetCodeGenerationOptions(languageServices), + CleanupOptions = options.GetCodeCleanupOptions(languageServices, allowImportsInHiddenRegions) + }; + + public static async ValueTask GetCodeGenerationOptionsAsync(this Document document, CancellationToken cancellationToken) + { + var configOptions = await document.GetAnalyzerConfigOptionsAsync(cancellationToken).ConfigureAwait(false); + return configOptions.GetCodeGenerationOptions(document.Project.GetExtendedLanguageServices().LanguageServices); + } + + public static async ValueTask GetCodeGenerationInfoAsync(this Document document, CodeGenerationContext context, CancellationToken cancellationToken) + { + Contract.ThrowIfNull(document.Project.ParseOptions); + + var options = await GetCodeGenerationOptionsAsync(document, cancellationToken).ConfigureAwait(false); + var service = document.GetRequiredLanguageService(); + return service.GetInfo(context, options, document.Project.ParseOptions); + } +} diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/IMethodSymbolExtensions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/IMethodSymbolExtensions.cs new file mode 100644 index 0000000000000..c13c6c3e09ccd --- /dev/null +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/IMethodSymbolExtensions.cs @@ -0,0 +1,142 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using Microsoft.CodeAnalysis.CodeGeneration; +using Microsoft.CodeAnalysis.LanguageService; +using Microsoft.CodeAnalysis.Shared.Utilities; +using Roslyn.Utilities; + +namespace Microsoft.CodeAnalysis.Shared.Extensions; + +internal static partial class IMethodSymbolExtensions +{ + public static IMethodSymbol EnsureNonConflictingNames( + this IMethodSymbol method, INamedTypeSymbol containingType, ISyntaxFactsService syntaxFacts) + { + // The method's type parameters may conflict with the type parameters in the type + // we're generating into. In that case, rename them. + var parameterNames = NameGenerator.EnsureUniqueness( + method.Parameters.SelectAsArray(p => p.Name), isCaseSensitive: syntaxFacts.IsCaseSensitive); + + var outerTypeParameterNames = + containingType.GetAllTypeParameters() + .Select(tp => tp.Name) + .Concat(method.Name) + .Concat(containingType.Name); + + var unusableNames = parameterNames.Concat(outerTypeParameterNames).ToSet( + syntaxFacts.IsCaseSensitive ? StringComparer.Ordinal : StringComparer.OrdinalIgnoreCase); + + var newTypeParameterNames = NameGenerator.EnsureUniqueness( + method.TypeParameters.SelectAsArray(tp => tp.Name), + n => !unusableNames.Contains(n)); + + var updatedMethod = method.RenameTypeParameters(newTypeParameterNames); + return updatedMethod.RenameParameters(parameterNames); + } + + public static IMethodSymbol RenameTypeParameters(this IMethodSymbol method, ImmutableArray newNames) + { + if (method.TypeParameters.Select(t => t.Name).SequenceEqual(newNames)) + { + return method; + } + + var typeGenerator = new TypeGenerator(); + var updatedTypeParameters = RenameTypeParameters( + method.TypeParameters, newNames, typeGenerator); + + var mapping = new Dictionary(SymbolEqualityComparer.Default); + for (var i = 0; i < method.TypeParameters.Length; i++) + { + mapping[method.TypeParameters[i]] = updatedTypeParameters[i]; + } + + return CodeGenerationSymbolFactory.CreateMethodSymbol( + method.ContainingType, + method.GetAttributes(), + method.DeclaredAccessibility, + method.GetSymbolModifiers(), + method.ReturnType.SubstituteTypes(mapping, typeGenerator), + method.RefKind, + method.ExplicitInterfaceImplementations, + method.Name, + updatedTypeParameters, + method.Parameters.SelectAsArray(p => + CodeGenerationSymbolFactory.CreateParameterSymbol(p.GetAttributes(), p.RefKind, p.IsParams, p.Type.SubstituteTypes(mapping, typeGenerator), p.Name, p.IsOptional, + p.HasExplicitDefaultValue, p.HasExplicitDefaultValue ? p.ExplicitDefaultValue : null))); + } + + public static IMethodSymbol RenameParameters( + this IMethodSymbol method, ImmutableArray parameterNames) + { + var parameterList = method.Parameters; + if (parameterList.Select(p => p.Name).SequenceEqual(parameterNames)) + { + return method; + } + + var parameters = parameterList.RenameParameters(parameterNames); + + return CodeGenerationSymbolFactory.CreateMethodSymbol( + method.ContainingType, + method.GetAttributes(), + method.DeclaredAccessibility, + method.GetSymbolModifiers(), + method.ReturnType, + method.RefKind, + method.ExplicitInterfaceImplementations, + method.Name, + method.TypeParameters, + parameters); + } + + private static ImmutableArray RenameTypeParameters( + ImmutableArray typeParameters, + ImmutableArray newNames, + ITypeGenerator typeGenerator) + { + // We generate the type parameter in two passes. The first creates the new type + // parameter. The second updates the constraints to point at this new type parameter. + var newTypeParameters = new List(); + + var mapping = new Dictionary(SymbolEqualityComparer.Default); + for (var i = 0; i < typeParameters.Length; i++) + { + var typeParameter = typeParameters[i]; + + var newTypeParameter = new CodeGenerationTypeParameterSymbol( + typeParameter.ContainingType, + typeParameter.GetAttributes(), + typeParameter.Variance, + newNames[i], + typeParameter.NullableAnnotation, + typeParameter.ConstraintTypes, + typeParameter.HasConstructorConstraint, + typeParameter.HasReferenceTypeConstraint, + typeParameter.HasValueTypeConstraint, + typeParameter.HasUnmanagedTypeConstraint, + typeParameter.HasNotNullConstraint, + typeParameter.AllowsRefLikeType, + typeParameter.Ordinal); + + newTypeParameters.Add(newTypeParameter); + mapping[typeParameter] = newTypeParameter; + } + + // Now we update the constraints. + foreach (var newTypeParameter in newTypeParameters) + { + newTypeParameter.ConstraintTypes = ImmutableArray.CreateRange(newTypeParameter.ConstraintTypes, t => t.SubstituteTypes(mapping, typeGenerator)); + } + + return newTypeParameters.Cast().ToImmutableArray(); + } +} diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/IParameterSymbolExtensions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/IParameterSymbolExtensions.cs new file mode 100644 index 0000000000000..0e1873f9f9fbb --- /dev/null +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/IParameterSymbolExtensions.cs @@ -0,0 +1,36 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Generic; +using System.Collections.Immutable; +using Microsoft.CodeAnalysis.CodeGeneration; + +namespace Microsoft.CodeAnalysis.Shared.Extensions; + +internal static partial class IParameterSymbolExtensions +{ + public static ImmutableArray RenameParameters(this IList parameters, ImmutableArray parameterNames) + { + var result = new FixedSizeArrayBuilder(parameters.Count); + for (var i = 0; i < parameterNames.Length; i++) + result.Add(parameters[i].RenameParameter(parameterNames[i])); + + return result.MoveToImmutable(); + } + + public static IParameterSymbol RenameParameter(this IParameterSymbol parameter, string parameterName) + { + return parameter.Name == parameterName + ? parameter + : CodeGenerationSymbolFactory.CreateParameterSymbol( + parameter.GetAttributes(), + parameter.RefKind, + parameter.IsParams, + parameter.Type, + parameterName, + parameter.IsOptional, + parameter.HasExplicitDefaultValue, + parameter.HasExplicitDefaultValue ? parameter.ExplicitDefaultValue : null); + } +} diff --git a/src/Workspaces/Core/Portable/Shared/Extensions/ITypeSymbolExtensions.CompilationTypeGenerator.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/ITypeSymbolExtensions.CompilationTypeGenerator.cs similarity index 100% rename from src/Workspaces/Core/Portable/Shared/Extensions/ITypeSymbolExtensions.CompilationTypeGenerator.cs rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/ITypeSymbolExtensions.CompilationTypeGenerator.cs diff --git a/src/Workspaces/Core/Portable/Shared/Extensions/ITypeSymbolExtensions.SubstituteTypesVisitor.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/ITypeSymbolExtensions.SubstituteTypesVisitor.cs similarity index 100% rename from src/Workspaces/Core/Portable/Shared/Extensions/ITypeSymbolExtensions.SubstituteTypesVisitor.cs rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/ITypeSymbolExtensions.SubstituteTypesVisitor.cs diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/ITypeSymbolExtensions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/ITypeSymbolExtensions.cs index 33a03578e4007..fd0642d85e4d1 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/ITypeSymbolExtensions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/ITypeSymbolExtensions.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; namespace Microsoft.CodeAnalysis.Shared.Extensions; @@ -23,4 +24,26 @@ public static IList GetReferencedTypeParameters( type?.Accept(new CollectTypeParameterSymbolsVisitor(result, onlyMethodTypeParameters: false)); return result; } + + [return: NotNullIfNotNull(parameterName: nameof(type))] + public static ITypeSymbol? SubstituteTypes( + this ITypeSymbol? type, + IDictionary mapping, + Compilation compilation) + where TType1 : ITypeSymbol + where TType2 : ITypeSymbol + { + return type.SubstituteTypes(mapping, new CompilationTypeGenerator(compilation)); + } + + [return: NotNullIfNotNull(parameterName: nameof(type))] + public static ITypeSymbol? SubstituteTypes( + this ITypeSymbol? type, + IDictionary mapping, + ITypeGenerator typeGenerator) + where TType1 : ITypeSymbol + where TType2 : ITypeSymbol + { + return type?.Accept(new SubstituteTypesVisitor(mapping, typeGenerator)); + } } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/SyntaxGeneratorExtensions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/SyntaxGeneratorExtensions.cs index 224eef7fde58f..14b498d91e046 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/SyntaxGeneratorExtensions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/SyntaxGeneratorExtensions.cs @@ -2,12 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System; using System.Collections.Generic; using System.Collections.Immutable; using Microsoft.CodeAnalysis.Editing; +using Microsoft.CodeAnalysis.Simplification; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.Shared.Extensions; @@ -86,4 +85,149 @@ private static ITypeSymbol GetType(Compilation compilation, ISymbol symbol) public static SyntaxNode IsPatternExpression(this SyntaxGeneratorInternal generator, SyntaxNode expression, SyntaxNode pattern) => generator.IsPatternExpression(expression, isToken: default, pattern); + + /// + /// Generates a call to a method *through* an existing field or property symbol. + /// + /// + public static SyntaxNode GenerateDelegateThroughMemberStatement( + this SyntaxGenerator generator, IMethodSymbol method, ISymbol throughMember) + { + var through = generator.MemberAccessExpression( + CreateDelegateThroughExpression(generator, method, throughMember), + method.IsGenericMethod + ? generator.GenericName(method.Name, method.TypeArguments) + : generator.IdentifierName(method.Name)); + + var invocationExpression = generator.InvocationExpression(through, generator.CreateArguments(method.Parameters)); + return method.ReturnsVoid + ? generator.ExpressionStatement(invocationExpression) + : generator.ReturnStatement(invocationExpression); + } + + public static SyntaxNode CreateDelegateThroughExpression( + this SyntaxGenerator generator, ISymbol member, ISymbol throughMember) + { + var name = generator.IdentifierName(throughMember.Name); + var through = throughMember.IsStatic + ? GenerateContainerName(generator, throughMember) + // If we're delegating through a primary constructor parameter, we cannot qualify the name at all. + : throughMember is IParameterSymbol + ? null + : generator.ThisExpression(); + + through = through is null ? name : generator.MemberAccessExpression(through, name); + + var throughMemberType = throughMember.GetMemberType(); + if (throughMemberType != null && + member.ContainingType is { TypeKind: TypeKind.Interface } interfaceBeingImplemented) + { + // In the case of 'implement interface through field / property', we need to know what + // interface we are implementing so that we can insert casts to this interface on every + // usage of the field in the generated code. Without these casts we would end up generating + // code that fails compilation in certain situations. + // + // For example consider the following code. + // class C : IReadOnlyList { int[] field; } + // When applying the 'implement interface through field' code fix in the above example, + // we need to generate the following code to implement the Count property on IReadOnlyList + // class C : IReadOnlyList { int[] field; int Count { get { ((IReadOnlyList)field).Count; } ...} + // as opposed to the following code which will fail to compile (because the array field + // doesn't have a property named .Count) - + // class C : IReadOnlyList { int[] field; int Count { get { field.Count; } ...} + // + // The 'InterfaceTypes' property on the state object always contains only one item + // in the case of C# i.e. it will contain exactly the interface we are trying to implement. + // This is also the case most of the time in the case of VB, except in certain error conditions + // (recursive / circular cases) where the span of the squiggle for the corresponding + // diagnostic (BC30149) changes and 'InterfaceTypes' ends up including all interfaces + // in the Implements clause. For the purposes of inserting the above cast, we ignore the + // uncommon case and optimize for the common one - in other words, we only apply the cast + // in cases where we can unambiguously figure out which interface we are trying to implement. + if (!throughMemberType.Equals(interfaceBeingImplemented)) + { + through = generator.CastExpression(interfaceBeingImplemented, + through.WithAdditionalAnnotations(Simplifier.Annotation)); + } + else if (throughMember is IPropertySymbol { IsStatic: false, ExplicitInterfaceImplementations: [var explicitlyImplementedProperty, ..] }) + { + // If we are implementing through an explicitly implemented property, we need to cast 'this' to + // the explicitly implemented interface type before calling the member, as in: + // ((IA)this).Prop.Member(); + // + var explicitImplementationCast = generator.CastExpression( + explicitlyImplementedProperty.ContainingType, + generator.ThisExpression()); + + through = generator.MemberAccessExpression(explicitImplementationCast, + generator.IdentifierName(explicitlyImplementedProperty.Name)); + + through = through.WithAdditionalAnnotations(Simplifier.Annotation); + } + } + + return through.WithAdditionalAnnotations(Simplifier.Annotation); + + // local functions + + static SyntaxNode GenerateContainerName(SyntaxGenerator factory, ISymbol throughMember) + { + var classOrStructType = throughMember.ContainingType; + return classOrStructType.IsGenericType + ? factory.GenericName(classOrStructType.Name, classOrStructType.TypeArguments) + : factory.IdentifierName(classOrStructType.Name); + } + } + + public static ImmutableArray GetGetAccessorStatements( + this SyntaxGenerator generator, Compilation compilation, + IPropertySymbol property, ISymbol? throughMember, bool preferAutoProperties) + { + if (throughMember != null) + { + var throughExpression = CreateDelegateThroughExpression(generator, property, throughMember); + var expression = property.IsIndexer + ? throughExpression + : generator.MemberAccessExpression( + throughExpression, generator.IdentifierName(property.Name)); + + if (property.Parameters.Length > 0) + { + var arguments = generator.CreateArguments(property.Parameters); + expression = generator.ElementAccessExpression(expression, arguments); + } + + return [generator.ReturnStatement(expression)]; + } + + return preferAutoProperties ? default : generator.CreateThrowNotImplementedStatementBlock(compilation); + } + + public static ImmutableArray GetSetAccessorStatements( + this SyntaxGenerator generator, Compilation compilation, + IPropertySymbol property, ISymbol? throughMember, bool preferAutoProperties) + { + if (throughMember != null) + { + var throughExpression = CreateDelegateThroughExpression(generator, property, throughMember); + var expression = property.IsIndexer + ? throughExpression + : generator.MemberAccessExpression( + throughExpression, generator.IdentifierName(property.Name)); + + if (property.Parameters.Length > 0) + { + var arguments = generator.CreateArguments(property.Parameters); + expression = generator.ElementAccessExpression(expression, arguments); + } + + expression = generator.AssignmentStatement(expression, generator.IdentifierName("value")); + + return [generator.ExpressionStatement(expression)]; + } + + return preferAutoProperties + ? default + : generator.CreateThrowNotImplementedStatementBlock(compilation); + } } diff --git a/src/Workspaces/Core/Portable/Formatting/ISyntaxFormattingService.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Formatting/ISyntaxFormattingService.cs similarity index 100% rename from src/Workspaces/Core/Portable/Formatting/ISyntaxFormattingService.cs rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Formatting/ISyntaxFormattingService.cs diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Formatting/SyntaxFormattingOptionsProviders.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Formatting/SyntaxFormattingOptionsProviders.cs index 8bbc96f499ceb..be9cf562bac4e 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Formatting/SyntaxFormattingOptionsProviders.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Formatting/SyntaxFormattingOptionsProviders.cs @@ -11,13 +11,11 @@ namespace Microsoft.CodeAnalysis.Formatting; internal static class SyntaxFormattingOptionsProviders { -#if !CODE_STYLE public static SyntaxFormattingOptions GetSyntaxFormattingOptions(this IOptionsReader options, Host.LanguageServices languageServices) => languageServices.GetRequiredService().GetFormattingOptions(options); public static ValueTask GetSyntaxFormattingOptionsAsync(this Document document, CancellationToken cancellationToken) - => GetSyntaxFormattingOptionsAsync(document, document.Project.Services.GetRequiredService(), cancellationToken); -#endif + => GetSyntaxFormattingOptionsAsync(document, document.GetRequiredLanguageService(), cancellationToken); public static async ValueTask GetSyntaxFormattingOptionsAsync(this Document document, ISyntaxFormatting formatting, CancellationToken cancellationToken) { diff --git a/src/Features/Core/Portable/Options/MemberDisplayOptions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Options/MemberDisplayOptions.cs similarity index 92% rename from src/Features/Core/Portable/Options/MemberDisplayOptions.cs rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Options/MemberDisplayOptions.cs index 67bb9061167d2..9fad0c04e94c7 100644 --- a/src/Features/Core/Portable/Options/MemberDisplayOptions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Options/MemberDisplayOptions.cs @@ -7,6 +7,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Options; +using Microsoft.CodeAnalysis.Shared.Extensions; namespace Microsoft.CodeAnalysis; @@ -24,7 +25,7 @@ internal readonly record struct MemberDisplayOptions() /// internal static class MemberDisplayOptionsStorage { - public static readonly OptionGroup TypeMemberGroup = new(name: "type_members", description: FeaturesResources.Type_members, priority: 3, parent: null); + public static readonly OptionGroup TypeMemberGroup = new(name: "type_members", description: WorkspaceExtensionsResources.Type_members, priority: 3, parent: null); public static readonly PerLanguageOption2 HideAdvancedMembers = new( "dotnet_hide_advanced_members", diff --git a/src/Workspaces/Core/Portable/Simplification/AbstractReducer.IExpressionRewriter.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Simplification/AbstractReducer.IExpressionRewriter.cs similarity index 100% rename from src/Workspaces/Core/Portable/Simplification/AbstractReducer.IExpressionRewriter.cs rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Simplification/AbstractReducer.IExpressionRewriter.cs diff --git a/src/Workspaces/Core/Portable/Simplification/AbstractReducer.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Simplification/AbstractReducer.cs similarity index 100% rename from src/Workspaces/Core/Portable/Simplification/AbstractReducer.cs rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Simplification/AbstractReducer.cs diff --git a/src/Workspaces/Core/Portable/Simplification/AbstractSimplificationService.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Simplification/AbstractSimplificationService.cs similarity index 100% rename from src/Workspaces/Core/Portable/Simplification/AbstractSimplificationService.cs rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Simplification/AbstractSimplificationService.cs diff --git a/src/Workspaces/Core/Portable/Simplification/ISimplificationService.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Simplification/ISimplificationService.cs similarity index 100% rename from src/Workspaces/Core/Portable/Simplification/ISimplificationService.cs rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Simplification/ISimplificationService.cs diff --git a/src/Workspaces/Core/Portable/Simplification/NodeOrTokenToReduce.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Simplification/NodeOrTokenToReduce.cs similarity index 100% rename from src/Workspaces/Core/Portable/Simplification/NodeOrTokenToReduce.cs rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Simplification/NodeOrTokenToReduce.cs diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Simplification/SimplifierOptionsProviders.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Simplification/SimplifierOptionsProviders.cs index d2e85d01ad8e6..9bb772509f3d5 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Simplification/SimplifierOptionsProviders.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Simplification/SimplifierOptionsProviders.cs @@ -11,13 +11,11 @@ namespace Microsoft.CodeAnalysis.Simplification; internal static class SimplifierOptionsProviders { -#if !CODE_STYLE public static SimplifierOptions GetSimplifierOptions(this IOptionsReader options, Host.LanguageServices languageServices) => languageServices.GetService()?.GetSimplifierOptions(options) ?? SimplifierOptions.CommonDefaults; public static ValueTask GetSimplifierOptionsAsync(this Document document, CancellationToken cancellationToken) - => GetSimplifierOptionsAsync(document, document.Project.Services.GetRequiredService(), cancellationToken); -#endif + => GetSimplifierOptionsAsync(document, document.GetRequiredLanguageService(), cancellationToken); public static async ValueTask GetSimplifierOptionsAsync(this Document document, ISimplification simplification, CancellationToken cancellationToken) { diff --git a/src/Workspaces/Core/Portable/Simplification/Simplifiers/AbstractMemberAccessExpressionSimplifier.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Simplification/Simplifiers/AbstractMemberAccessExpressionSimplifier.cs similarity index 100% rename from src/Workspaces/Core/Portable/Simplification/Simplifiers/AbstractMemberAccessExpressionSimplifier.cs rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Simplification/Simplifiers/AbstractMemberAccessExpressionSimplifier.cs diff --git a/src/Workspaces/Core/Portable/Simplification/Simplifiers/AbstractSimplifier.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Simplification/Simplifiers/AbstractSimplifier.cs similarity index 100% rename from src/Workspaces/Core/Portable/Simplification/Simplifiers/AbstractSimplifier.cs rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Simplification/Simplifiers/AbstractSimplifier.cs diff --git a/src/Workspaces/Core/Portable/Shared/Utilities/RoslynParallel.NetFramework.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Utilities/RoslynParallel.NetFramework.cs similarity index 99% rename from src/Workspaces/Core/Portable/Shared/Utilities/RoslynParallel.NetFramework.cs rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Utilities/RoslynParallel.NetFramework.cs index d24e62bb1e4eb..dd626976d8108 100644 --- a/src/Workspaces/Core/Portable/Shared/Utilities/RoslynParallel.NetFramework.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Utilities/RoslynParallel.NetFramework.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +// + #if !NET #pragma warning disable CA1068 // CancellationToken parameters must come last @@ -401,12 +403,12 @@ private abstract class ForEachAsyncState : TaskCompletionSourceSemaphore used to provide exclusive access to the enumerator. - private readonly SemaphoreSlim? _lock; + private readonly SemaphoreSlim _lock; /// The number of outstanding workers. When this hits 0, the operation has completed. private int _completionRefCount; /// Any exceptions incurred during execution. - private List? _exceptions; + private List _exceptions; /// The number of workers that may still be created. private int _remainingDop; diff --git a/src/Workspaces/Core/Portable/Shared/Utilities/RoslynParallel.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Utilities/RoslynParallel.cs similarity index 100% rename from src/Workspaces/Core/Portable/Shared/Utilities/RoslynParallel.cs rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Utilities/RoslynParallel.cs diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensions.projitems b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensions.projitems index 8521b221696d8..a7ea9d3e6c450 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensions.projitems +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensions.projitems @@ -9,6 +9,14 @@ Microsoft.CodeAnalysis.Shared + + + + + + + + @@ -78,6 +86,11 @@ + + + + + @@ -117,9 +130,13 @@ + + + + @@ -158,4 +175,7 @@ + + + \ No newline at end of file diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensionsResources.resx b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensionsResources.resx index 4ca939845df3e..eaf14008d4e5d 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensionsResources.resx +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensionsResources.resx @@ -192,4 +192,7 @@ Namespace can not be added in this destination. + + Type members + \ No newline at end of file diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.cs.xlf b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.cs.xlf index fbabe19a86657..90dc5de14631f 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.cs.xlf +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.cs.xlf @@ -122,6 +122,11 @@ Řešení neobsahuje zadaný dokument. + + Type members + Type members + + Warning: Declaration changes scope and may change meaning. Upozornění: Deklarace mění rozsah a může změnit význam. diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.de.xlf b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.de.xlf index cffd3da698896..db2b11e0940f8 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.de.xlf +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.de.xlf @@ -122,6 +122,11 @@ Die Lösung enthält nicht das angegebene Dokument. + + Type members + Type members + + Warning: Declaration changes scope and may change meaning. Warnung: Die Deklaration ändert den Bereich und möglicherweise die Bedeutung. diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.es.xlf b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.es.xlf index 07164c7c23837..184c80b11953a 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.es.xlf +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.es.xlf @@ -122,6 +122,11 @@ La solución no contiene el documento especificado. + + Type members + Type members + + Warning: Declaration changes scope and may change meaning. Advertencia: La declaración cambia el ámbito y puede cambiar el significado. diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.fr.xlf b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.fr.xlf index dbddeb1912b98..b9f3e3985e244 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.fr.xlf +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.fr.xlf @@ -122,6 +122,11 @@ La solution ne contient pas le document spécifié. + + Type members + Type members + + Warning: Declaration changes scope and may change meaning. Avertissement : La déclaration change la portée et éventuellement la signification. diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.it.xlf b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.it.xlf index a2c78b22b50ab..92dc61b79a0ff 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.it.xlf +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.it.xlf @@ -122,6 +122,11 @@ La soluzione non contiene il documento specificato. + + Type members + Type members + + Warning: Declaration changes scope and may change meaning. Avviso: la dichiarazione implica la modifica dell'ambito e potrebbe modificare il significato. diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.ja.xlf b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.ja.xlf index 47ac48e3daa75..8db67bbc29874 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.ja.xlf +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.ja.xlf @@ -122,6 +122,11 @@ ソリューションには、指定されたドキュメントがありません。 + + Type members + Type members + + Warning: Declaration changes scope and may change meaning. 警告: 宣言によりスコープが変更され、意味が変わる可能性があります。 diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.ko.xlf b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.ko.xlf index 9206614edb5a7..29356090134d0 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.ko.xlf +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.ko.xlf @@ -122,6 +122,11 @@ 솔루션에 지정한 문서가 포함되어 있지 않습니다. + + Type members + Type members + + Warning: Declaration changes scope and may change meaning. 경고: 선언 시 범위가 변경되고 의미가 변경될 수 있습니다. diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.pl.xlf b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.pl.xlf index eab56886bbe3e..b7b5a09a32825 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.pl.xlf +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.pl.xlf @@ -122,6 +122,11 @@ Rozwiązanie nie zawiera określonego dokumentu. + + Type members + Type members + + Warning: Declaration changes scope and may change meaning. Ostrzeżenie: deklaracja zmienia zakres i może zmienić znaczenie. diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.pt-BR.xlf b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.pt-BR.xlf index 4d335c670f6d8..4aaa5994bfda8 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.pt-BR.xlf +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.pt-BR.xlf @@ -122,6 +122,11 @@ A solução não contém o documento especificado. + + Type members + Type members + + Warning: Declaration changes scope and may change meaning. Aviso: a declaração altera e escopo e pode alterar o significado. diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.ru.xlf b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.ru.xlf index 5222a6f599619..3718d3ef2bd3a 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.ru.xlf +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.ru.xlf @@ -122,6 +122,11 @@ Указанный документ отсутствует в решении. + + Type members + Type members + + Warning: Declaration changes scope and may change meaning. Предупреждение. Объявление изменяет область и может изменить значение. diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.tr.xlf b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.tr.xlf index d9c8984990dc5..b6e1d6d96a6f5 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.tr.xlf +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.tr.xlf @@ -122,6 +122,11 @@ Çözüm belirtilen belgeyi içermiyor. + + Type members + Type members + + Warning: Declaration changes scope and may change meaning. Uyarı: Bildirim, kapsamı değiştiriyor ve anlamı da değiştirebilir. diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.zh-Hans.xlf b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.zh-Hans.xlf index 5fe06e2b21b63..dd6b61e5dcb94 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.zh-Hans.xlf +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.zh-Hans.xlf @@ -122,6 +122,11 @@ 解决方案不包含指定的文档。 + + Type members + Type members + + Warning: Declaration changes scope and may change meaning. 警告: 声明更改了作用域,并且可能更改含义。 diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.zh-Hant.xlf b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.zh-Hant.xlf index 38c4ef5ba363d..ec56d8adbb821 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.zh-Hant.xlf +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/xlf/WorkspaceExtensionsResources.zh-Hant.xlf @@ -122,6 +122,11 @@ 此方案不包含指定的文件。 + + Type members + Type members + + Warning: Declaration changes scope and may change meaning. 警告: 宣告會變更範圍,且可能會變更意義。 diff --git a/src/Workspaces/VisualBasic/Portable/CodeGeneration/ArgumentGenerator.vb b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/ArgumentGenerator.vb similarity index 100% rename from src/Workspaces/VisualBasic/Portable/CodeGeneration/ArgumentGenerator.vb rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/ArgumentGenerator.vb diff --git a/src/Workspaces/VisualBasic/Portable/CodeGeneration/AttributeGenerator.vb b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/AttributeGenerator.vb similarity index 100% rename from src/Workspaces/VisualBasic/Portable/CodeGeneration/AttributeGenerator.vb rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/AttributeGenerator.vb diff --git a/src/Workspaces/VisualBasic/Portable/CodeGeneration/ConstructorGenerator.vb b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/ConstructorGenerator.vb similarity index 100% rename from src/Workspaces/VisualBasic/Portable/CodeGeneration/ConstructorGenerator.vb rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/ConstructorGenerator.vb diff --git a/src/Workspaces/VisualBasic/Portable/CodeGeneration/ConversionGenerator.vb b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/ConversionGenerator.vb similarity index 100% rename from src/Workspaces/VisualBasic/Portable/CodeGeneration/ConversionGenerator.vb rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/ConversionGenerator.vb diff --git a/src/Workspaces/VisualBasic/Portable/CodeGeneration/EnumMemberGenerator.vb b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/EnumMemberGenerator.vb similarity index 100% rename from src/Workspaces/VisualBasic/Portable/CodeGeneration/EnumMemberGenerator.vb rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/EnumMemberGenerator.vb diff --git a/src/Workspaces/VisualBasic/Portable/CodeGeneration/EventGenerator.vb b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/EventGenerator.vb similarity index 84% rename from src/Workspaces/VisualBasic/Portable/CodeGeneration/EventGenerator.vb rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/EventGenerator.vb index 8c42db193a173..9056e0381f15d 100644 --- a/src/Workspaces/VisualBasic/Portable/CodeGeneration/EventGenerator.vb +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/EventGenerator.vb @@ -44,10 +44,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration Return FirstMethod(members) End Function - Friend Function AddEventTo(destination As TypeBlockSyntax, - [event] As IEventSymbol, - options As CodeGenerationContextInfo, - availableIndices As IList(Of Boolean)) As TypeBlockSyntax + Friend Function AddEventTo( + destination As TypeBlockSyntax, + [event] As IEventSymbol, + options As CodeGenerationContextInfo, + availableIndices As IList(Of Boolean)) As TypeBlockSyntax Dim eventDeclaration = GenerateEventDeclaration([event], GetDestination(destination), options) Dim members = Insert(destination.Members, eventDeclaration, options, availableIndices, @@ -59,9 +60,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration Return FixTerminators(destination.WithMembers(members)) End Function - Public Function GenerateEventDeclaration([event] As IEventSymbol, - destination As CodeGenerationDestination, - options As CodeGenerationContextInfo) As DeclarationStatementSyntax + Public Function GenerateEventDeclaration( + [event] As IEventSymbol, + destination As CodeGenerationDestination, + options As CodeGenerationContextInfo) As DeclarationStatementSyntax Dim reusableSyntax = GetReuseableSyntaxNodeForSymbol(Of DeclarationStatementSyntax)([event], options) If reusableSyntax IsNot Nothing Then Return reusableSyntax @@ -72,9 +74,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration Return AddFormatterAndCodeGeneratorAnnotationsTo(ConditionallyAddDocumentationCommentTo(declaration, [event], options)) End Function - Private Function GenerateEventDeclarationWorker([event] As IEventSymbol, - destination As CodeGenerationDestination, - options As CodeGenerationContextInfo) As DeclarationStatementSyntax + Private Function GenerateEventDeclarationWorker( + [event] As IEventSymbol, + destination As CodeGenerationDestination, + options As CodeGenerationContextInfo) As DeclarationStatementSyntax If options.Context.GenerateMethodBodies AndAlso ([event].AddMethod IsNot Nothing OrElse [event].RemoveMethod IsNot Nothing OrElse [event].RaiseMethod IsNot Nothing) Then @@ -101,29 +104,28 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration New SyntaxList(Of StatementSyntax), GenerateStatements([event].RaiseMethod)) - Dim generator As VisualBasicSyntaxGenerator = New VisualBasicSyntaxGenerator() - + Dim generator = options.Generator Dim invoke = DirectCast([event].Type, INamedTypeSymbol)?.DelegateInvokeMethod Dim parameters = If( invoke IsNot Nothing, invoke.Parameters.Select(Function(p) generator.ParameterDeclaration(p)), Nothing) - Dim result = DirectCast(generator.CustomEventDeclarationWithRaise( - [event].Name, - generator.TypeExpression([event].Type), - [event].DeclaredAccessibility, - DeclarationModifiers.From([event]), - parameters, - addStatements, - removeStatements, - raiseStatements), EventBlockSyntax) + Dim result = DirectCast(VisualBasicSyntaxGeneratorInternal.CustomEventDeclarationWithRaise( + [event].Name, + generator.TypeExpression([event].Type), + [event].DeclaredAccessibility, + DeclarationModifiers.From([event]), + parameters, + addStatements, + removeStatements, + raiseStatements), EventBlockSyntax) result = DirectCast( result.WithAttributeLists(GenerateAttributeBlocks([event].GetAttributes(), options)), EventBlockSyntax) result = DirectCast(result.WithModifiers(GenerateModifiers([event], destination, options)), EventBlockSyntax) Dim explicitInterface = [event].ExplicitInterfaceImplementations.FirstOrDefault() - If (explicitInterface IsNot Nothing) + If (explicitInterface IsNot Nothing) Then result = result.WithEventStatement( result.EventStatement.WithImplementsClause(GenerateImplementsClause(explicitInterface))) End If diff --git a/src/Workspaces/VisualBasic/Portable/CodeGeneration/ExpressionGenerator.StringPiece.vb b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/ExpressionGenerator.StringPiece.vb similarity index 100% rename from src/Workspaces/VisualBasic/Portable/CodeGeneration/ExpressionGenerator.StringPiece.vb rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/ExpressionGenerator.StringPiece.vb diff --git a/src/Workspaces/VisualBasic/Portable/CodeGeneration/ExpressionGenerator.StringPieceKind.vb b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/ExpressionGenerator.StringPieceKind.vb similarity index 100% rename from src/Workspaces/VisualBasic/Portable/CodeGeneration/ExpressionGenerator.StringPieceKind.vb rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/ExpressionGenerator.StringPieceKind.vb diff --git a/src/Workspaces/VisualBasic/Portable/CodeGeneration/ExpressionGenerator.vb b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/ExpressionGenerator.vb similarity index 100% rename from src/Workspaces/VisualBasic/Portable/CodeGeneration/ExpressionGenerator.vb rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/ExpressionGenerator.vb diff --git a/src/Workspaces/VisualBasic/Portable/CodeGeneration/FieldGenerator.vb b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/FieldGenerator.vb similarity index 100% rename from src/Workspaces/VisualBasic/Portable/CodeGeneration/FieldGenerator.vb rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/FieldGenerator.vb diff --git a/src/Workspaces/VisualBasic/Portable/CodeGeneration/MethodGenerator.vb b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/MethodGenerator.vb similarity index 100% rename from src/Workspaces/VisualBasic/Portable/CodeGeneration/MethodGenerator.vb rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/MethodGenerator.vb diff --git a/src/Workspaces/VisualBasic/Portable/CodeGeneration/NamedTypeGenerator.vb b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/NamedTypeGenerator.vb similarity index 100% rename from src/Workspaces/VisualBasic/Portable/CodeGeneration/NamedTypeGenerator.vb rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/NamedTypeGenerator.vb diff --git a/src/Workspaces/VisualBasic/Portable/CodeGeneration/NamespaceGenerator.vb b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/NamespaceGenerator.vb similarity index 96% rename from src/Workspaces/VisualBasic/Portable/CodeGeneration/NamespaceGenerator.vb rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/NamespaceGenerator.vb index 78ea3cacf4973..8915c423b2d56 100644 --- a/src/Workspaces/VisualBasic/Portable/CodeGeneration/NamespaceGenerator.vb +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/NamespaceGenerator.vb @@ -19,7 +19,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration cancellationToken As CancellationToken) As CompilationUnitSyntax Dim declaration = GenerateNamespaceDeclaration(service, [namespace], options, cancellationToken) If Not TypeOf declaration Is NamespaceBlockSyntax Then - Throw New ArgumentException(VBWorkspaceResources.Namespace_can_not_be_added_in_this_destination) + Throw New ArgumentException(WorkspaceExtensionsResources.Namespace_can_not_be_added_in_this_destination) End If Dim members = Insert(destination.Members, DirectCast(declaration, StatementSyntax), options, availableIndices) @@ -34,7 +34,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration cancellationToken As CancellationToken) As NamespaceBlockSyntax Dim declaration = GenerateNamespaceDeclaration(service, [namespace], options, cancellationToken) If Not TypeOf declaration Is NamespaceBlockSyntax Then - Throw New ArgumentException(VBWorkspaceResources.Namespace_can_not_be_added_in_this_destination) + Throw New ArgumentException(WorkspaceExtensionsResources.Namespace_can_not_be_added_in_this_destination) End If Dim members = Insert(destination.Members, DirectCast(declaration, StatementSyntax), options, availableIndices) diff --git a/src/Workspaces/VisualBasic/Portable/CodeGeneration/OperatorGenerator.vb b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/OperatorGenerator.vb similarity index 100% rename from src/Workspaces/VisualBasic/Portable/CodeGeneration/OperatorGenerator.vb rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/OperatorGenerator.vb diff --git a/src/Workspaces/VisualBasic/Portable/CodeGeneration/ParameterGenerator.vb b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/ParameterGenerator.vb similarity index 100% rename from src/Workspaces/VisualBasic/Portable/CodeGeneration/ParameterGenerator.vb rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/ParameterGenerator.vb diff --git a/src/Workspaces/VisualBasic/Portable/CodeGeneration/PropertyGenerator.vb b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/PropertyGenerator.vb similarity index 100% rename from src/Workspaces/VisualBasic/Portable/CodeGeneration/PropertyGenerator.vb rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/PropertyGenerator.vb diff --git a/src/Workspaces/VisualBasic/Portable/CodeGeneration/StatementGenerator.vb b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/StatementGenerator.vb similarity index 100% rename from src/Workspaces/VisualBasic/Portable/CodeGeneration/StatementGenerator.vb rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/StatementGenerator.vb diff --git a/src/Workspaces/VisualBasic/Portable/CodeGeneration/TypeParameterGenerator.vb b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/TypeParameterGenerator.vb similarity index 100% rename from src/Workspaces/VisualBasic/Portable/CodeGeneration/TypeParameterGenerator.vb rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/TypeParameterGenerator.vb diff --git a/src/Workspaces/VisualBasic/Portable/CodeGeneration/VisualBasicCodeGenerationContextInfo.vb b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/VisualBasicCodeGenerationContextInfo.vb similarity index 100% rename from src/Workspaces/VisualBasic/Portable/CodeGeneration/VisualBasicCodeGenerationContextInfo.vb rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/VisualBasicCodeGenerationContextInfo.vb diff --git a/src/Workspaces/VisualBasic/Portable/CodeGeneration/VisualBasicCodeGenerationHelpers.vb b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/VisualBasicCodeGenerationHelpers.vb similarity index 100% rename from src/Workspaces/VisualBasic/Portable/CodeGeneration/VisualBasicCodeGenerationHelpers.vb rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/VisualBasicCodeGenerationHelpers.vb diff --git a/src/Workspaces/VisualBasic/Portable/CodeGeneration/VisualBasicCodeGenerationService.vb b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/VisualBasicCodeGenerationService.vb similarity index 99% rename from src/Workspaces/VisualBasic/Portable/CodeGeneration/VisualBasicCodeGenerationService.vb rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/VisualBasicCodeGenerationService.vb index b1298c0f3ed96..b01506434ada5 100644 --- a/src/Workspaces/VisualBasic/Portable/CodeGeneration/VisualBasicCodeGenerationService.vb +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/VisualBasicCodeGenerationService.vb @@ -17,8 +17,7 @@ Imports Microsoft.CodeAnalysis.VisualBasic.LanguageService Imports Microsoft.CodeAnalysis.VisualBasic.Syntax Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration - - Friend Class VisualBasicCodeGenerationService + Friend NotInheritable Class VisualBasicCodeGenerationService Inherits AbstractCodeGenerationService(Of VisualBasicCodeGenerationContextInfo) Public Sub New(languageServices As LanguageServices) @@ -247,7 +246,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration End If End Function - Private Overloads Shared Function AddParametersToMethod(Of TDeclarationNode As SyntaxNode)( + Private Overloads Function AddParametersToMethod(Of TDeclarationNode As SyntaxNode)( methodStatement As MethodBaseSyntax, methodBlock As MethodBlockBaseSyntax, parameters As IEnumerable(Of IParameterSymbol), @@ -282,7 +281,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration Return DirectCast(DirectCast(result, Object), TDeclarationNode) End Function - Private Overloads Shared Function AddParametersToProperty(Of TDeclarationNode As SyntaxNode)( + Private Overloads Function AddParametersToProperty(Of TDeclarationNode As SyntaxNode)( propertyBlock As PropertyBlockSyntax, parameters As IEnumerable(Of IParameterSymbol), options As VisualBasicCodeGenerationContextInfo, @@ -293,7 +292,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration Return DirectCast(newPropertyBlock, TDeclarationNode) End Function - Private Overloads Shared Function AddParameterToMethodBase(Of TMethodBase As MethodBaseSyntax)( + Private Overloads Function AddParameterToMethodBase(Of TMethodBase As MethodBaseSyntax)( methodBase As TMethodBase, parameters As IEnumerable(Of IParameterSymbol), options As VisualBasicCodeGenerationContextInfo, @@ -304,7 +303,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration Dim parameterCount = If(parameterList IsNot Nothing, parameterList.Parameters.Count, 0) Dim seenOptional = parameterCount > 0 AndAlso parameterList.Parameters(parameterCount - 1).Default IsNot Nothing - Dim editor = New SyntaxEditor(methodBase, VisualBasicSyntaxGenerator.Instance) + Dim editor = New SyntaxEditor(methodBase, Me.LanguageServices.SolutionServices) For Each parameter In parameters Dim parameterSyntax = ParameterGenerator.GenerateParameter(parameter, seenOptional, options) diff --git a/src/Workspaces/VisualBasic/Portable/CodeGeneration/VisualBasicCodeGenerationServiceFactory.vb b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/VisualBasicCodeGenerationServiceFactory.vb similarity index 100% rename from src/Workspaces/VisualBasic/Portable/CodeGeneration/VisualBasicCodeGenerationServiceFactory.vb rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/VisualBasicCodeGenerationServiceFactory.vb diff --git a/src/Workspaces/VisualBasic/Portable/CodeGeneration/VisualBasicDeclarationComparer.vb b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/VisualBasicDeclarationComparer.vb similarity index 100% rename from src/Workspaces/VisualBasic/Portable/CodeGeneration/VisualBasicDeclarationComparer.vb rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/VisualBasicDeclarationComparer.vb diff --git a/src/Workspaces/VisualBasic/Portable/CodeGeneration/VisualBasicFlagsEnumGenerator.vb b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/VisualBasicFlagsEnumGenerator.vb similarity index 100% rename from src/Workspaces/VisualBasic/Portable/CodeGeneration/VisualBasicFlagsEnumGenerator.vb rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/CodeGeneration/VisualBasicFlagsEnumGenerator.vb diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/LanguageServices/VisualBasicSyntaxGeneratorInternal.vb b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/LanguageServices/VisualBasicSyntaxGeneratorInternal.vb index de4f014b21889..7baacaddcb1a8 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/LanguageServices/VisualBasicSyntaxGeneratorInternal.vb +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/LanguageServices/VisualBasicSyntaxGeneratorInternal.vb @@ -4,6 +4,7 @@ Imports System.Composition Imports System.Diagnostics.CodeAnalysis +Imports Microsoft.CodeAnalysis Imports Microsoft.CodeAnalysis.Editing Imports Microsoft.CodeAnalysis.Host.Mef Imports Microsoft.CodeAnalysis.LanguageService @@ -16,7 +17,17 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration Friend Class VisualBasicSyntaxGeneratorInternal Inherits SyntaxGeneratorInternal - Public Shared ReadOnly Instance As SyntaxGeneratorInternal = New VisualBasicSyntaxGeneratorInternal() + Public Shared ReadOnly Instance As New VisualBasicSyntaxGeneratorInternal() + + Public Shared ReadOnly s_fieldModifiers As DeclarationModifiers = DeclarationModifiers.Const Or DeclarationModifiers.[New] Or DeclarationModifiers.ReadOnly Or DeclarationModifiers.Static Or DeclarationModifiers.WithEvents + Public Shared ReadOnly s_methodModifiers As DeclarationModifiers = DeclarationModifiers.Abstract Or DeclarationModifiers.Async Or DeclarationModifiers.[New] Or DeclarationModifiers.Override Or DeclarationModifiers.Partial Or DeclarationModifiers.Sealed Or DeclarationModifiers.Static Or DeclarationModifiers.Virtual + Public Shared ReadOnly s_constructorModifiers As DeclarationModifiers = DeclarationModifiers.Static + Public Shared ReadOnly s_propertyModifiers As DeclarationModifiers = DeclarationModifiers.Abstract Or DeclarationModifiers.[New] Or DeclarationModifiers.Override Or DeclarationModifiers.ReadOnly Or DeclarationModifiers.WriteOnly Or DeclarationModifiers.Sealed Or DeclarationModifiers.Static Or DeclarationModifiers.Virtual + Public Shared ReadOnly s_indexerModifiers As DeclarationModifiers = DeclarationModifiers.Abstract Or DeclarationModifiers.[New] Or DeclarationModifiers.Override Or DeclarationModifiers.ReadOnly Or DeclarationModifiers.WriteOnly Or DeclarationModifiers.Sealed Or DeclarationModifiers.Static Or DeclarationModifiers.Virtual + Public Shared ReadOnly s_classModifiers As DeclarationModifiers = DeclarationModifiers.Abstract Or DeclarationModifiers.[New] Or DeclarationModifiers.Partial Or DeclarationModifiers.Sealed Or DeclarationModifiers.Static + Public Shared ReadOnly s_structModifiers As DeclarationModifiers = DeclarationModifiers.[New] Or DeclarationModifiers.Partial + Public Shared ReadOnly s_interfaceModifiers As DeclarationModifiers = DeclarationModifiers.[New] Or DeclarationModifiers.Partial + Public Shared ReadOnly s_accessorModifiers As DeclarationModifiers = DeclarationModifiers.Abstract Or DeclarationModifiers.[New] Or DeclarationModifiers.Override Or DeclarationModifiers.Virtual @@ -146,6 +157,291 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration Return SyntaxFactory.TypeOfIsNotExpression(DirectCast(expression, ExpressionSyntax), DirectCast(type, TypeSyntax)) End Function + Public Shared Function CustomEventDeclarationWithRaise( + name As String, + type As SyntaxNode, + Optional accessibility As Accessibility = Accessibility.NotApplicable, + Optional modifiers As DeclarationModifiers = Nothing, + Optional parameters As IEnumerable(Of SyntaxNode) = Nothing, + Optional addAccessorStatements As IEnumerable(Of SyntaxNode) = Nothing, + Optional removeAccessorStatements As IEnumerable(Of SyntaxNode) = Nothing, + Optional raiseAccessorStatements As IEnumerable(Of SyntaxNode) = Nothing) As SyntaxNode + + Dim accessors = New List(Of AccessorBlockSyntax)() + + If modifiers.IsAbstract Then + addAccessorStatements = Nothing + removeAccessorStatements = Nothing + raiseAccessorStatements = Nothing + Else + If addAccessorStatements Is Nothing Then + addAccessorStatements = SpecializedCollections.EmptyEnumerable(Of SyntaxNode)() + End If + + If removeAccessorStatements Is Nothing Then + removeAccessorStatements = SpecializedCollections.EmptyEnumerable(Of SyntaxNode)() + End If + + If raiseAccessorStatements Is Nothing Then + raiseAccessorStatements = SpecializedCollections.EmptyEnumerable(Of SyntaxNode)() + End If + End If + + accessors.Add(CreateAddHandlerAccessorBlock(type, addAccessorStatements)) + accessors.Add(CreateRemoveHandlerAccessorBlock(type, removeAccessorStatements)) + accessors.Add(CreateRaiseEventAccessorBlock(parameters, raiseAccessorStatements)) + + Dim evStatement = SyntaxFactory.EventStatement( + attributeLists:=Nothing, + modifiers:=GetModifierList(accessibility, modifiers And GetAllowedModifiers(SyntaxKind.EventStatement), declaration:=Nothing, DeclarationKind.Event), + customKeyword:=SyntaxFactory.Token(SyntaxKind.CustomKeyword), + eventKeyword:=SyntaxFactory.Token(SyntaxKind.EventKeyword), + identifier:=name.ToIdentifierToken(), + parameterList:=Nothing, + asClause:=SyntaxFactory.SimpleAsClause(DirectCast(type, TypeSyntax)), + implementsClause:=Nothing) + + Return SyntaxFactory.EventBlock( + eventStatement:=evStatement, + accessors:=SyntaxFactory.List(accessors), + endEventStatement:=SyntaxFactory.EndEventStatement()) + End Function + + Friend Shared Function CreateAddHandlerAccessorBlock(delegateType As SyntaxNode, statements As IEnumerable(Of SyntaxNode)) As AccessorBlockSyntax + Dim asClause = SyntaxFactory.SimpleAsClause(DirectCast(delegateType, TypeSyntax)) + + Dim valueParameter = SyntaxFactory.Parameter( + attributeLists:=Nothing, + modifiers:=Nothing, + identifier:=SyntaxFactory.ModifiedIdentifier("value"), + asClause:=asClause, + [default]:=Nothing) + + Return SyntaxFactory.AccessorBlock( + SyntaxKind.AddHandlerAccessorBlock, + SyntaxFactory.AccessorStatement( + kind:=SyntaxKind.AddHandlerAccessorStatement, + attributeLists:=Nothing, + modifiers:=Nothing, + accessorKeyword:=SyntaxFactory.Token(SyntaxKind.AddHandlerKeyword), + parameterList:=SyntaxFactory.ParameterList(SyntaxFactory.SingletonSeparatedList(valueParameter))), + GetStatementList(statements), + SyntaxFactory.EndAddHandlerStatement()) + End Function + + Friend Shared Function CreateRemoveHandlerAccessorBlock(delegateType As SyntaxNode, statements As IEnumerable(Of SyntaxNode)) As AccessorBlockSyntax + Dim asClause = SyntaxFactory.SimpleAsClause(DirectCast(delegateType, TypeSyntax)) + + Dim valueParameter = SyntaxFactory.Parameter( + attributeLists:=Nothing, + modifiers:=Nothing, + identifier:=SyntaxFactory.ModifiedIdentifier("value"), + asClause:=asClause, + [default]:=Nothing) + + Return SyntaxFactory.AccessorBlock( + SyntaxKind.RemoveHandlerAccessorBlock, + SyntaxFactory.AccessorStatement( + kind:=SyntaxKind.RemoveHandlerAccessorStatement, + attributeLists:=Nothing, + modifiers:=Nothing, + accessorKeyword:=SyntaxFactory.Token(SyntaxKind.RemoveHandlerKeyword), + parameterList:=SyntaxFactory.ParameterList(SyntaxFactory.SingletonSeparatedList(valueParameter))), + GetStatementList(statements), + SyntaxFactory.EndRemoveHandlerStatement()) + End Function + + Friend Shared Function CreateRaiseEventAccessorBlock(parameters As IEnumerable(Of SyntaxNode), statements As IEnumerable(Of SyntaxNode)) As AccessorBlockSyntax + Dim parameterList = GetParameterList(parameters) + + Return SyntaxFactory.AccessorBlock( + SyntaxKind.RaiseEventAccessorBlock, + SyntaxFactory.AccessorStatement( + kind:=SyntaxKind.RaiseEventAccessorStatement, + attributeLists:=Nothing, + modifiers:=Nothing, + accessorKeyword:=SyntaxFactory.Token(SyntaxKind.RaiseEventKeyword), + parameterList:=parameterList), + GetStatementList(statements), + SyntaxFactory.EndRaiseEventStatement()) + End Function + + Friend Shared Function GetStatementList(nodes As IEnumerable(Of SyntaxNode)) As SyntaxList(Of StatementSyntax) + If nodes Is Nothing Then + Return Nothing + Else + Return SyntaxFactory.List(nodes.Select(AddressOf AsStatement)) + End If + End Function + + Friend Shared Function AsStatement(node As SyntaxNode) As StatementSyntax + Dim expr = TryCast(node, ExpressionSyntax) + If expr IsNot Nothing Then + Return SyntaxFactory.ExpressionStatement(expr) + Else + Return DirectCast(node, StatementSyntax) + End If + End Function + + Friend Shared Function GetAllowedModifiers(kind As SyntaxKind) As DeclarationModifiers + Select Case kind + Case SyntaxKind.ClassBlock, SyntaxKind.ClassStatement + Return s_classModifiers + + Case SyntaxKind.EnumBlock, SyntaxKind.EnumStatement + Return DeclarationModifiers.[New] + + Case SyntaxKind.DelegateFunctionStatement, SyntaxKind.DelegateSubStatement + Return DeclarationModifiers.[New] + + Case SyntaxKind.InterfaceBlock, SyntaxKind.InterfaceStatement + Return s_interfaceModifiers + + Case SyntaxKind.StructureBlock, SyntaxKind.StructureStatement + Return s_structModifiers + + Case SyntaxKind.FunctionBlock, + SyntaxKind.FunctionStatement, + SyntaxKind.SubBlock, + SyntaxKind.SubStatement, + SyntaxKind.OperatorBlock, + SyntaxKind.OperatorStatement + Return s_methodModifiers + + Case SyntaxKind.ConstructorBlock, + SyntaxKind.SubNewStatement + Return s_constructorModifiers + + Case SyntaxKind.FieldDeclaration + Return s_fieldModifiers + + Case SyntaxKind.PropertyBlock, + SyntaxKind.PropertyStatement + Return s_propertyModifiers + + Case SyntaxKind.EventBlock, + SyntaxKind.EventStatement + Return s_propertyModifiers + + Case SyntaxKind.GetAccessorBlock, + SyntaxKind.GetAccessorStatement, + SyntaxKind.SetAccessorBlock, + SyntaxKind.SetAccessorStatement, + SyntaxKind.AddHandlerAccessorBlock, + SyntaxKind.AddHandlerAccessorStatement, + SyntaxKind.RemoveHandlerAccessorBlock, + SyntaxKind.RemoveHandlerAccessorStatement, + SyntaxKind.RaiseEventAccessorBlock, + SyntaxKind.RaiseEventAccessorStatement + Return s_accessorModifiers + + Case SyntaxKind.EnumMemberDeclaration + Case SyntaxKind.Parameter + Case SyntaxKind.LocalDeclarationStatement + Case Else + Return DeclarationModifiers.None + End Select + End Function + + Friend Shared Function GetParameterList(parameters As IEnumerable(Of SyntaxNode)) As ParameterListSyntax + Return If(parameters IsNot Nothing, SyntaxFactory.ParameterList(SyntaxFactory.SeparatedList(parameters.Cast(Of ParameterSyntax)())), SyntaxFactory.ParameterList()) + End Function + + Friend Shared Function GetModifierList(accessibility As Accessibility, modifiers As DeclarationModifiers, declaration As SyntaxNode, kind As DeclarationKind, Optional isDefault As Boolean = False) As SyntaxTokenList + Dim _list = SyntaxFactory.TokenList() + + ' While partial must always be last in C#, its preferred position in VB is to be first, + ' even before accessibility modifiers. This order is enforced by line commit. + If modifiers.IsPartial Then + _list = _list.Add(SyntaxFactory.Token(SyntaxKind.PartialKeyword)) + End If + + If isDefault Then + _list = _list.Add(SyntaxFactory.Token(SyntaxKind.DefaultKeyword)) + End If + + Select Case (accessibility) + Case Accessibility.Internal + _list = _list.Add(SyntaxFactory.Token(SyntaxKind.FriendKeyword)) + Case Accessibility.Public + _list = _list.Add(SyntaxFactory.Token(SyntaxKind.PublicKeyword)) + Case Accessibility.Private + _list = _list.Add(SyntaxFactory.Token(SyntaxKind.PrivateKeyword)) + Case Accessibility.Protected + _list = _list.Add(SyntaxFactory.Token(SyntaxKind.ProtectedKeyword)) + Case Accessibility.ProtectedOrInternal + _list = _list.Add(SyntaxFactory.Token(SyntaxKind.FriendKeyword)).Add(SyntaxFactory.Token(SyntaxKind.ProtectedKeyword)) + Case Accessibility.ProtectedAndInternal + _list = _list.Add(SyntaxFactory.Token(SyntaxKind.PrivateKeyword)).Add(SyntaxFactory.Token(SyntaxKind.ProtectedKeyword)) + Case Accessibility.NotApplicable + Case Else + Throw New NotSupportedException(String.Format("Accessibility '{0}' not supported.", accessibility)) + End Select + + Dim isClass = kind = DeclarationKind.Class OrElse declaration.IsKind(SyntaxKind.ClassStatement) + If modifiers.IsAbstract Then + If isClass Then + _list = _list.Add(SyntaxFactory.Token(SyntaxKind.MustInheritKeyword)) + Else + _list = _list.Add(SyntaxFactory.Token(SyntaxKind.MustOverrideKeyword)) + End If + End If + + If modifiers.IsNew Then + _list = _list.Add(SyntaxFactory.Token(SyntaxKind.ShadowsKeyword)) + End If + + If modifiers.IsSealed Then + If isClass Then + _list = _list.Add(SyntaxFactory.Token(SyntaxKind.NotInheritableKeyword)) + Else + _list = _list.Add(SyntaxFactory.Token(SyntaxKind.NotOverridableKeyword)) + End If + End If + + If modifiers.IsOverride Then + _list = _list.Add(SyntaxFactory.Token(SyntaxKind.OverridesKeyword)) + End If + + If modifiers.IsVirtual Then + _list = _list.Add(SyntaxFactory.Token(SyntaxKind.OverridableKeyword)) + End If + + If modifiers.IsStatic Then + _list = _list.Add(SyntaxFactory.Token(SyntaxKind.SharedKeyword)) + End If + + If modifiers.IsAsync Then + _list = _list.Add(SyntaxFactory.Token(SyntaxKind.AsyncKeyword)) + End If + + If modifiers.IsConst Then + _list = _list.Add(SyntaxFactory.Token(SyntaxKind.ConstKeyword)) + End If + + If modifiers.IsReadOnly Then + _list = _list.Add(SyntaxFactory.Token(SyntaxKind.ReadOnlyKeyword)) + End If + + If modifiers.IsWriteOnly Then + _list = _list.Add(SyntaxFactory.Token(SyntaxKind.WriteOnlyKeyword)) + End If + + If modifiers.IsUnsafe Then + Throw New NotSupportedException("Unsupported modifier") + ''''_list = _list.Add(SyntaxFactory.Token(SyntaxKind.UnsafeKeyword)) + End If + + If modifiers.IsWithEvents Then + _list = _list.Add(SyntaxFactory.Token(SyntaxKind.WithEventsKeyword)) + End If + + If (kind = DeclarationKind.Field AndAlso _list.Count = 0) Then + _list = _list.Add(SyntaxFactory.Token(SyntaxKind.DimKeyword)) + End If + + Return _list + End Function #Region "Patterns" Public Overrides Function SupportsPatterns(options As ParseOptions) As Boolean diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/VisualBasicWorkspaceExtensions.projitems b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/VisualBasicWorkspaceExtensions.projitems index aeb2f1557f279..55a0b8011a5a4 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/VisualBasicWorkspaceExtensions.projitems +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/VisualBasicWorkspaceExtensions.projitems @@ -9,6 +9,30 @@ Microsoft.CodeAnalysis.VisualBasic.Shared + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Workspaces/VisualBasic/Portable/CodeGeneration/VisualBasicSyntaxGenerator.vb b/src/Workspaces/VisualBasic/Portable/CodeGeneration/VisualBasicSyntaxGenerator.vb index 25ad7483d6050..6bb6fff41a5af 100644 --- a/src/Workspaces/VisualBasic/Portable/CodeGeneration/VisualBasicSyntaxGenerator.vb +++ b/src/Workspaces/VisualBasic/Portable/CodeGeneration/VisualBasicSyntaxGenerator.vb @@ -249,21 +249,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration ) End Function - Private Function GetStatementList(nodes As IEnumerable(Of SyntaxNode)) As SyntaxList(Of StatementSyntax) - If nodes Is Nothing Then - Return Nothing - Else - Return SyntaxFactory.List(nodes.Select(AddressOf AsStatement)) - End If + Private Shared Function GetStatementList(nodes As IEnumerable(Of SyntaxNode)) As SyntaxList(Of StatementSyntax) + Return VisualBasicSyntaxGeneratorInternal.GetStatementList(nodes) End Function - Private Function AsStatement(node As SyntaxNode) As StatementSyntax - Dim expr = TryCast(node, ExpressionSyntax) - If expr IsNot Nothing Then - Return SyntaxFactory.ExpressionStatement(expr) - Else - Return DirectCast(node, StatementSyntax) - End If + Private Shared Function AsStatement(node As SyntaxNode) As StatementSyntax + Return VisualBasicSyntaxGeneratorInternal.AsStatement(node) End Function Public Overloads Overrides Function InvocationExpression(expression As SyntaxNode, arguments As IEnumerable(Of SyntaxNode)) As SyntaxNode @@ -691,81 +682,15 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration #Region "Declarations" - Private Shared ReadOnly s_fieldModifiers As DeclarationModifiers = DeclarationModifiers.Const Or DeclarationModifiers.[New] Or DeclarationModifiers.ReadOnly Or DeclarationModifiers.Static Or DeclarationModifiers.WithEvents - Private Shared ReadOnly s_methodModifiers As DeclarationModifiers = DeclarationModifiers.Abstract Or DeclarationModifiers.Async Or DeclarationModifiers.[New] Or DeclarationModifiers.Override Or DeclarationModifiers.Partial Or DeclarationModifiers.Sealed Or DeclarationModifiers.Static Or DeclarationModifiers.Virtual - Private Shared ReadOnly s_constructorModifiers As DeclarationModifiers = DeclarationModifiers.Static - Private Shared ReadOnly s_propertyModifiers As DeclarationModifiers = DeclarationModifiers.Abstract Or DeclarationModifiers.[New] Or DeclarationModifiers.Override Or DeclarationModifiers.ReadOnly Or DeclarationModifiers.WriteOnly Or DeclarationModifiers.Sealed Or DeclarationModifiers.Static Or DeclarationModifiers.Virtual - Private Shared ReadOnly s_indexerModifiers As DeclarationModifiers = DeclarationModifiers.Abstract Or DeclarationModifiers.[New] Or DeclarationModifiers.Override Or DeclarationModifiers.ReadOnly Or DeclarationModifiers.WriteOnly Or DeclarationModifiers.Sealed Or DeclarationModifiers.Static Or DeclarationModifiers.Virtual - Private Shared ReadOnly s_classModifiers As DeclarationModifiers = DeclarationModifiers.Abstract Or DeclarationModifiers.[New] Or DeclarationModifiers.Partial Or DeclarationModifiers.Sealed Or DeclarationModifiers.Static - Private Shared ReadOnly s_structModifiers As DeclarationModifiers = DeclarationModifiers.[New] Or DeclarationModifiers.Partial - Private Shared ReadOnly s_interfaceModifiers As DeclarationModifiers = DeclarationModifiers.[New] Or DeclarationModifiers.Partial - Private Shared ReadOnly s_accessorModifiers As DeclarationModifiers = DeclarationModifiers.Abstract Or DeclarationModifiers.[New] Or DeclarationModifiers.Override Or DeclarationModifiers.Virtual - - Private Shared Function GetAllowedModifiers(kind As SyntaxKind) As DeclarationModifiers - Select Case kind - Case SyntaxKind.ClassBlock, SyntaxKind.ClassStatement - Return s_classModifiers - - Case SyntaxKind.EnumBlock, SyntaxKind.EnumStatement - Return DeclarationModifiers.[New] - - Case SyntaxKind.DelegateFunctionStatement, SyntaxKind.DelegateSubStatement - Return DeclarationModifiers.[New] - - Case SyntaxKind.InterfaceBlock, SyntaxKind.InterfaceStatement - Return s_interfaceModifiers - - Case SyntaxKind.StructureBlock, SyntaxKind.StructureStatement - Return s_structModifiers - - Case SyntaxKind.FunctionBlock, - SyntaxKind.FunctionStatement, - SyntaxKind.SubBlock, - SyntaxKind.SubStatement, - SyntaxKind.OperatorBlock, - SyntaxKind.OperatorStatement - Return s_methodModifiers - - Case SyntaxKind.ConstructorBlock, - SyntaxKind.SubNewStatement - Return s_constructorModifiers - - Case SyntaxKind.FieldDeclaration - Return s_fieldModifiers - - Case SyntaxKind.PropertyBlock, - SyntaxKind.PropertyStatement - Return s_propertyModifiers - - Case SyntaxKind.EventBlock, - SyntaxKind.EventStatement - Return s_propertyModifiers - - Case SyntaxKind.GetAccessorBlock, - SyntaxKind.GetAccessorStatement, - SyntaxKind.SetAccessorBlock, - SyntaxKind.SetAccessorStatement, - SyntaxKind.AddHandlerAccessorBlock, - SyntaxKind.AddHandlerAccessorStatement, - SyntaxKind.RemoveHandlerAccessorBlock, - SyntaxKind.RemoveHandlerAccessorStatement, - SyntaxKind.RaiseEventAccessorBlock, - SyntaxKind.RaiseEventAccessorStatement - Return s_accessorModifiers - - Case SyntaxKind.EnumMemberDeclaration - Case SyntaxKind.Parameter - Case SyntaxKind.LocalDeclarationStatement - Case Else - Return DeclarationModifiers.None - End Select + Friend Shared Function GetAllowedModifiers(kind As SyntaxKind) As DeclarationModifiers + Return VisualBasicSyntaxGeneratorInternal.GetAllowedModifiers(kind) End Function Public Overrides Function FieldDeclaration(name As String, type As SyntaxNode, Optional accessibility As Accessibility = Nothing, Optional modifiers As DeclarationModifiers = Nothing, Optional initializer As SyntaxNode = Nothing) As SyntaxNode modifiers = If(modifiers.IsConst(), modifiers.WithIsReadOnly(False), modifiers) Return SyntaxFactory.FieldDeclaration( attributeLists:=Nothing, - modifiers:=GetModifierList(accessibility, modifiers And s_fieldModifiers, declaration:=Nothing, DeclarationKind.Field), + modifiers:=GetModifierList(accessibility, modifiers And VisualBasicSyntaxGeneratorInternal.s_fieldModifiers, declaration:=Nothing, DeclarationKind.Field), declarators:=SyntaxFactory.SingletonSeparatedList(VisualBasicSyntaxGeneratorInternal.VariableDeclarator(type, name.ToModifiedIdentifier, initializer))) End Function @@ -781,7 +706,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration Dim statement = SyntaxFactory.MethodStatement( kind:=If(returnType Is Nothing, SyntaxKind.SubStatement, SyntaxKind.FunctionStatement), attributeLists:=Nothing, - modifiers:=GetModifierList(accessibility, modifiers And s_methodModifiers, declaration:=Nothing, DeclarationKind.Method), + modifiers:=GetModifierList(accessibility, modifiers And VisualBasicSyntaxGeneratorInternal.s_methodModifiers, declaration:=Nothing, DeclarationKind.Method), subOrFunctionKeyword:=If(returnType Is Nothing, SyntaxFactory.Token(SyntaxKind.SubKeyword), SyntaxFactory.Token(SyntaxKind.FunctionKeyword)), identifier:=identifier.ToIdentifierToken(), typeParameterList:=GetTypeParameters(typeParameters), @@ -817,7 +742,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration Dim parameterList = GetParameterList(parameters) Dim vbSyntaxKind As SyntaxKind = VisualBasic.SyntaxFacts.GetOperatorKind(operatorName) Dim operatorToken = SyntaxFactory.Token(vbSyntaxKind) - Dim modifierList As SyntaxTokenList = GetModifierList(accessibility, modifiers And s_methodModifiers, declaration:=Nothing, DeclarationKind.Operator) + Dim modifierList As SyntaxTokenList = GetModifierList(accessibility, modifiers And VisualBasicSyntaxGeneratorInternal.s_methodModifiers, declaration:=Nothing, DeclarationKind.Operator) If vbSyntaxKind = SyntaxKind.CTypeKeyword Then modifierList = modifierList.Add(SyntaxFactory.Token( @@ -896,7 +821,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration End Function Private Shared Function GetParameterList(parameters As IEnumerable(Of SyntaxNode)) As ParameterListSyntax - Return If(parameters IsNot Nothing, SyntaxFactory.ParameterList(SyntaxFactory.SeparatedList(parameters.Cast(Of ParameterSyntax)())), SyntaxFactory.ParameterList()) + Return VisualBasicSyntaxGeneratorInternal.GetParameterList(parameters) End Function Private Protected Overrides Function ParameterDeclaration( @@ -1015,7 +940,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration Dim asClause = SyntaxFactory.SimpleAsClause(DirectCast(type, TypeSyntax)) Dim statement = SyntaxFactory.PropertyStatement( attributeLists:=Nothing, - modifiers:=GetModifierList(accessibility, modifiers And s_propertyModifiers, declaration:=Nothing, DeclarationKind.Property), + modifiers:=GetModifierList(accessibility, modifiers And VisualBasicSyntaxGeneratorInternal.s_propertyModifiers, declaration:=Nothing, DeclarationKind.Property), identifier:=name.ToIdentifierToken(), parameterList:=Nothing, asClause:=asClause, @@ -1048,7 +973,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration Dim asClause = SyntaxFactory.SimpleAsClause(DirectCast(type, TypeSyntax)) Dim statement = SyntaxFactory.PropertyStatement( attributeLists:=Nothing, - modifiers:=GetModifierList(accessibility, modifiers And s_indexerModifiers, declaration:=Nothing, DeclarationKind.Indexer, isDefault:=True), + modifiers:=GetModifierList(accessibility, modifiers And VisualBasicSyntaxGeneratorInternal.s_indexerModifiers, declaration:=Nothing, DeclarationKind.Indexer, isDefault:=True), identifier:=SyntaxFactory.Identifier("Item"), parameterList:=SyntaxFactory.ParameterList(SyntaxFactory.SeparatedList(parameters.Cast(Of ParameterSyntax))), asClause:=asClause, @@ -1075,22 +1000,22 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration End If End Function - Private Function AccessorBlock(kind As SyntaxKind, statements As IEnumerable(Of SyntaxNode), type As SyntaxNode) As AccessorBlockSyntax + Private Shared Function AccessorBlock(kind As SyntaxKind, statements As IEnumerable(Of SyntaxNode), type As SyntaxNode) As AccessorBlockSyntax Select Case kind Case SyntaxKind.GetAccessorBlock Return CreateGetAccessorBlock(statements) Case SyntaxKind.SetAccessorBlock Return CreateSetAccessorBlock(type, statements) Case SyntaxKind.AddHandlerAccessorBlock - Return CreateAddHandlerAccessorBlock(type, statements) + Return VisualBasicSyntaxGeneratorInternal.CreateAddHandlerAccessorBlock(type, statements) Case SyntaxKind.RemoveHandlerAccessorBlock - Return CreateRemoveHandlerAccessorBlock(type, statements) + Return VisualBasicSyntaxGeneratorInternal.CreateRemoveHandlerAccessorBlock(type, statements) Case Else Return Nothing End Select End Function - Private Function CreateGetAccessorBlock(statements As IEnumerable(Of SyntaxNode)) As AccessorBlockSyntax + Private Shared Function CreateGetAccessorBlock(statements As IEnumerable(Of SyntaxNode)) As AccessorBlockSyntax Return SyntaxFactory.AccessorBlock( SyntaxKind.GetAccessorBlock, SyntaxFactory.AccessorStatement(SyntaxKind.GetAccessorStatement, SyntaxFactory.Token(SyntaxKind.GetKeyword)), @@ -1098,7 +1023,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration SyntaxFactory.EndGetStatement()) End Function - Private Function CreateSetAccessorBlock(type As SyntaxNode, statements As IEnumerable(Of SyntaxNode)) As AccessorBlockSyntax + Private Shared Function CreateSetAccessorBlock(type As SyntaxNode, statements As IEnumerable(Of SyntaxNode)) As AccessorBlockSyntax Dim asClause = SyntaxFactory.SimpleAsClause(DirectCast(type, TypeSyntax)) Dim valueParameter = SyntaxFactory.Parameter( @@ -1120,65 +1045,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration SyntaxFactory.EndSetStatement()) End Function - Private Function CreateAddHandlerAccessorBlock(delegateType As SyntaxNode, statements As IEnumerable(Of SyntaxNode)) As AccessorBlockSyntax - Dim asClause = SyntaxFactory.SimpleAsClause(DirectCast(delegateType, TypeSyntax)) - - Dim valueParameter = SyntaxFactory.Parameter( - attributeLists:=Nothing, - modifiers:=Nothing, - identifier:=SyntaxFactory.ModifiedIdentifier("value"), - asClause:=asClause, - [default]:=Nothing) - - Return SyntaxFactory.AccessorBlock( - SyntaxKind.AddHandlerAccessorBlock, - SyntaxFactory.AccessorStatement( - kind:=SyntaxKind.AddHandlerAccessorStatement, - attributeLists:=Nothing, - modifiers:=Nothing, - accessorKeyword:=SyntaxFactory.Token(SyntaxKind.AddHandlerKeyword), - parameterList:=SyntaxFactory.ParameterList(SyntaxFactory.SingletonSeparatedList(valueParameter))), - GetStatementList(statements), - SyntaxFactory.EndAddHandlerStatement()) - End Function - - Private Function CreateRemoveHandlerAccessorBlock(delegateType As SyntaxNode, statements As IEnumerable(Of SyntaxNode)) As AccessorBlockSyntax - Dim asClause = SyntaxFactory.SimpleAsClause(DirectCast(delegateType, TypeSyntax)) - - Dim valueParameter = SyntaxFactory.Parameter( - attributeLists:=Nothing, - modifiers:=Nothing, - identifier:=SyntaxFactory.ModifiedIdentifier("value"), - asClause:=asClause, - [default]:=Nothing) - - Return SyntaxFactory.AccessorBlock( - SyntaxKind.RemoveHandlerAccessorBlock, - SyntaxFactory.AccessorStatement( - kind:=SyntaxKind.RemoveHandlerAccessorStatement, - attributeLists:=Nothing, - modifiers:=Nothing, - accessorKeyword:=SyntaxFactory.Token(SyntaxKind.RemoveHandlerKeyword), - parameterList:=SyntaxFactory.ParameterList(SyntaxFactory.SingletonSeparatedList(valueParameter))), - GetStatementList(statements), - SyntaxFactory.EndRemoveHandlerStatement()) - End Function - - Private Function CreateRaiseEventAccessorBlock(parameters As IEnumerable(Of SyntaxNode), statements As IEnumerable(Of SyntaxNode)) As AccessorBlockSyntax - Dim parameterList = GetParameterList(parameters) - - Return SyntaxFactory.AccessorBlock( - SyntaxKind.RaiseEventAccessorBlock, - SyntaxFactory.AccessorStatement( - kind:=SyntaxKind.RaiseEventAccessorStatement, - attributeLists:=Nothing, - modifiers:=Nothing, - accessorKeyword:=SyntaxFactory.Token(SyntaxKind.RaiseEventKeyword), - parameterList:=parameterList), - GetStatementList(statements), - SyntaxFactory.EndRaiseEventStatement()) - End Function - Public Overrides Function AsPublicInterfaceImplementation(declaration As SyntaxNode, interfaceTypeName As SyntaxNode, interfaceMemberName As String) As SyntaxNode Return Isolate(declaration, Function(decl) AsPublicInterfaceImplementationInternal(decl, interfaceTypeName, interfaceMemberName)) End Function @@ -1354,7 +1220,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration Return SyntaxFactory.ConstructorBlock( subNewStatement:=SyntaxFactory.SubNewStatement( attributeLists:=Nothing, - modifiers:=GetModifierList(accessibility, modifiers And s_constructorModifiers, declaration:=Nothing, DeclarationKind.Constructor), + modifiers:=GetModifierList(accessibility, modifiers And VisualBasicSyntaxGeneratorInternal.s_constructorModifiers, declaration:=Nothing, DeclarationKind.Constructor), parameterList:=If(parameters IsNot Nothing, SyntaxFactory.ParameterList(SyntaxFactory.SeparatedList(parameters.Cast(Of ParameterSyntax)())), SyntaxFactory.ParameterList())), statements:=stats) End Function @@ -1391,7 +1257,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration Return SyntaxFactory.ClassBlock( classStatement:=SyntaxFactory.ClassStatement( attributeLists:=Nothing, - modifiers:=GetModifierList(accessibility, modifiers And s_classModifiers, declaration:=Nothing, DeclarationKind.Class), + modifiers:=GetModifierList(accessibility, modifiers And VisualBasicSyntaxGeneratorInternal.s_classModifiers, declaration:=Nothing, DeclarationKind.Class), identifier:=name.ToIdentifierToken(), typeParameterList:=GetTypeParameters(typeParameters)), [inherits]:=If(baseType IsNot Nothing, SyntaxFactory.SingletonList(SyntaxFactory.InheritsStatement(DirectCast(baseType, TypeSyntax))), Nothing), @@ -1428,7 +1294,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration Return SyntaxFactory.StructureBlock( structureStatement:=SyntaxFactory.StructureStatement( attributeLists:=Nothing, - modifiers:=GetModifierList(accessibility, modifiers And s_structModifiers, declaration:=Nothing, DeclarationKind.Struct), + modifiers:=GetModifierList(accessibility, modifiers And VisualBasicSyntaxGeneratorInternal.s_structModifiers, declaration:=Nothing, DeclarationKind.Struct), identifier:=name.ToIdentifierToken(), typeParameterList:=GetTypeParameters(typeParameters)), [inherits]:=Nothing, @@ -1707,6 +1573,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration Return compilationUnit.Attributes(0).AttributeLists End If End If + Return Flatten(declaration.GetAttributeLists()) End Function @@ -1752,6 +1619,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration If Not declaration.IsKind(SyntaxKind.CompilationUnit) Then Return attributes End If + Return SyntaxFactory.List(attributes.Select(AddressOf WithAssemblyTargets)) End Function @@ -2692,100 +2560,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration Return WithModifierTokens(declaration, Merge(tokens, newTokens)) End Function - Private Shared Function GetModifierList(accessibility As Accessibility, modifiers As DeclarationModifiers, declaration As SyntaxNode, kind As DeclarationKind, Optional isDefault As Boolean = False) As SyntaxTokenList - Dim _list = SyntaxFactory.TokenList() - - ' While partial must always be last in C#, its preferred position in VB is to be first, - ' even before accessibility modifiers. This order is enforced by line commit. - If modifiers.IsPartial Then - _list = _list.Add(SyntaxFactory.Token(SyntaxKind.PartialKeyword)) - End If - - If isDefault Then - _list = _list.Add(SyntaxFactory.Token(SyntaxKind.DefaultKeyword)) - End If - - Select Case (accessibility) - Case Accessibility.Internal - _list = _list.Add(SyntaxFactory.Token(SyntaxKind.FriendKeyword)) - Case Accessibility.Public - _list = _list.Add(SyntaxFactory.Token(SyntaxKind.PublicKeyword)) - Case Accessibility.Private - _list = _list.Add(SyntaxFactory.Token(SyntaxKind.PrivateKeyword)) - Case Accessibility.Protected - _list = _list.Add(SyntaxFactory.Token(SyntaxKind.ProtectedKeyword)) - Case Accessibility.ProtectedOrInternal - _list = _list.Add(SyntaxFactory.Token(SyntaxKind.FriendKeyword)).Add(SyntaxFactory.Token(SyntaxKind.ProtectedKeyword)) - Case Accessibility.ProtectedAndInternal - _list = _list.Add(SyntaxFactory.Token(SyntaxKind.PrivateKeyword)).Add(SyntaxFactory.Token(SyntaxKind.ProtectedKeyword)) - Case Accessibility.NotApplicable - Case Else - Throw New NotSupportedException(String.Format("Accessibility '{0}' not supported.", accessibility)) - End Select - - Dim isClass = kind = DeclarationKind.Class OrElse declaration.IsKind(SyntaxKind.ClassStatement) - If modifiers.IsAbstract Then - If isClass Then - _list = _list.Add(SyntaxFactory.Token(SyntaxKind.MustInheritKeyword)) - Else - _list = _list.Add(SyntaxFactory.Token(SyntaxKind.MustOverrideKeyword)) - End If - End If - - If modifiers.IsNew Then - _list = _list.Add(SyntaxFactory.Token(SyntaxKind.ShadowsKeyword)) - End If - - If modifiers.IsSealed Then - If isClass Then - _list = _list.Add(SyntaxFactory.Token(SyntaxKind.NotInheritableKeyword)) - Else - _list = _list.Add(SyntaxFactory.Token(SyntaxKind.NotOverridableKeyword)) - End If - End If - - If modifiers.IsOverride Then - _list = _list.Add(SyntaxFactory.Token(SyntaxKind.OverridesKeyword)) - End If - - If modifiers.IsVirtual Then - _list = _list.Add(SyntaxFactory.Token(SyntaxKind.OverridableKeyword)) - End If - - If modifiers.IsStatic Then - _list = _list.Add(SyntaxFactory.Token(SyntaxKind.SharedKeyword)) - End If - - If modifiers.IsAsync Then - _list = _list.Add(SyntaxFactory.Token(SyntaxKind.AsyncKeyword)) - End If - - If modifiers.IsConst Then - _list = _list.Add(SyntaxFactory.Token(SyntaxKind.ConstKeyword)) - End If - - If modifiers.IsReadOnly Then - _list = _list.Add(SyntaxFactory.Token(SyntaxKind.ReadOnlyKeyword)) - End If - - If modifiers.IsWriteOnly Then - _list = _list.Add(SyntaxFactory.Token(SyntaxKind.WriteOnlyKeyword)) - End If - - If modifiers.IsUnsafe Then - Throw New NotSupportedException("Unsupported modifier") - ''''_list = _list.Add(SyntaxFactory.Token(SyntaxKind.UnsafeKeyword)) - End If - - If modifiers.IsWithEvents Then - _list = _list.Add(SyntaxFactory.Token(SyntaxKind.WithEventsKeyword)) - End If - - If (kind = DeclarationKind.Field AndAlso _list.Count = 0) Then - _list = _list.Add(SyntaxFactory.Token(SyntaxKind.DimKeyword)) - End If - - Return _list + Friend Shared Function GetModifierList(accessibility As Accessibility, modifiers As DeclarationModifiers, declaration As SyntaxNode, kind As DeclarationKind, Optional isDefault As Boolean = False) As SyntaxTokenList + Return VisualBasicSyntaxGeneratorInternal.GetModifierList(accessibility, modifiers, declaration, kind, isDefault) End Function Private Protected Overrides Function TypeParameter(name As String) As SyntaxNode @@ -3045,7 +2821,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration Return Isolate(declaration, Function(d) WithExpressionInternal(d, expression)) End Function - Private Function WithExpressionInternal(declaration As SyntaxNode, expression As SyntaxNode) As SyntaxNode + Private Shared Function WithExpressionInternal(declaration As SyntaxNode, expression As SyntaxNode) As SyntaxNode Dim expr = DirectCast(expression, ExpressionSyntax) Select Case declaration.Kind @@ -3267,7 +3043,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration Return Isolate(declaration, Function(d) WithStatementsInternal(d, statements)) End Function - Private Function WithStatementsInternal(declaration As SyntaxNode, statements As IEnumerable(Of SyntaxNode)) As SyntaxNode + Private Shared Function WithStatementsInternal(declaration As SyntaxNode, statements As IEnumerable(Of SyntaxNode)) As SyntaxNode Dim list = GetStatementList(statements) Select Case declaration.Kind Case SyntaxKind.FunctionBlock, @@ -3407,7 +3183,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration accessor = DirectCast(Me.WithStatements(accessor, statements), AccessorBlockSyntax) Return Me.WithAccessorBlock(declaration, kind, accessor) ElseIf CanHaveAccessors(declaration.Kind) Then - accessor = Me.AccessorBlock(kind, statements, Me.ClearTrivia(Me.GetType(declaration))) + accessor = AccessorBlock(kind, statements, Me.ClearTrivia(Me.GetType(declaration))) Return Me.WithAccessorBlock(declaration, kind, accessor) Else Return declaration @@ -3464,57 +3240,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration Optional addAccessorStatements As IEnumerable(Of SyntaxNode) = Nothing, Optional removeAccessorStatements As IEnumerable(Of SyntaxNode) = Nothing) As SyntaxNode - Return CustomEventDeclarationWithRaise(name, type, accessibility, modifiers, parameters, addAccessorStatements, removeAccessorStatements) - End Function - - Public Function CustomEventDeclarationWithRaise( - name As String, - type As SyntaxNode, - Optional accessibility As Accessibility = Accessibility.NotApplicable, - Optional modifiers As DeclarationModifiers = Nothing, - Optional parameters As IEnumerable(Of SyntaxNode) = Nothing, - Optional addAccessorStatements As IEnumerable(Of SyntaxNode) = Nothing, - Optional removeAccessorStatements As IEnumerable(Of SyntaxNode) = Nothing, - Optional raiseAccessorStatements As IEnumerable(Of SyntaxNode) = Nothing) As SyntaxNode - - Dim accessors = New List(Of AccessorBlockSyntax)() - - If modifiers.IsAbstract Then - addAccessorStatements = Nothing - removeAccessorStatements = Nothing - raiseAccessorStatements = Nothing - Else - If addAccessorStatements Is Nothing Then - addAccessorStatements = SpecializedCollections.EmptyEnumerable(Of SyntaxNode)() - End If - - If removeAccessorStatements Is Nothing Then - removeAccessorStatements = SpecializedCollections.EmptyEnumerable(Of SyntaxNode)() - End If - - If raiseAccessorStatements Is Nothing Then - raiseAccessorStatements = SpecializedCollections.EmptyEnumerable(Of SyntaxNode)() - End If - End If - - accessors.Add(CreateAddHandlerAccessorBlock(type, addAccessorStatements)) - accessors.Add(CreateRemoveHandlerAccessorBlock(type, removeAccessorStatements)) - accessors.Add(CreateRaiseEventAccessorBlock(parameters, raiseAccessorStatements)) - - Dim evStatement = SyntaxFactory.EventStatement( - attributeLists:=Nothing, - modifiers:=GetModifierList(accessibility, modifiers And GetAllowedModifiers(SyntaxKind.EventStatement), declaration:=Nothing, DeclarationKind.Event), - customKeyword:=SyntaxFactory.Token(SyntaxKind.CustomKeyword), - eventKeyword:=SyntaxFactory.Token(SyntaxKind.EventKeyword), - identifier:=name.ToIdentifierToken(), - parameterList:=Nothing, - asClause:=SyntaxFactory.SimpleAsClause(DirectCast(type, TypeSyntax)), - implementsClause:=Nothing) - - Return SyntaxFactory.EventBlock( - eventStatement:=evStatement, - accessors:=SyntaxFactory.List(accessors), - endEventStatement:=SyntaxFactory.EndEventStatement()) + Return VisualBasicSyntaxGeneratorInternal.CustomEventDeclarationWithRaise( + name, type, accessibility, modifiers, parameters, addAccessorStatements, removeAccessorStatements) End Function Public Overrides Function GetAttributeArguments(attributeDeclaration As SyntaxNode) As IReadOnlyList(Of SyntaxNode) diff --git a/src/Workspaces/VisualBasic/Portable/VBWorkspaceResources.resx b/src/Workspaces/VisualBasic/Portable/VBWorkspaceResources.resx index b040162d4149e..43f8dc0e878d5 100644 --- a/src/Workspaces/VisualBasic/Portable/VBWorkspaceResources.resx +++ b/src/Workspaces/VisualBasic/Portable/VBWorkspaceResources.resx @@ -117,9 +117,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - Namespace can not be added in this destination. - Only attributes, expressions or statements can be made explicit diff --git a/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.cs.xlf b/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.cs.xlf index a5bb92f2b56b6..8f1c14134a046 100644 --- a/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.cs.xlf +++ b/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.cs.xlf @@ -2,11 +2,6 @@ - - Namespace can not be added in this destination. - Obor názvů nejde přidat do tohoto cílového umístění. - - Only attributes, expressions or statements can be made explicit Jako explicitní jde nastavit jenom atributy, výrazy nebo příkazy. diff --git a/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.de.xlf b/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.de.xlf index b7655c60b9bec..3b85f06265d2b 100644 --- a/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.de.xlf +++ b/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.de.xlf @@ -2,11 +2,6 @@ - - Namespace can not be added in this destination. - Namespace kann zu diesem Ziel nicht hinzugefügt werden. - - Only attributes, expressions or statements can be made explicit Nur Attribute, Ausdrücke oder Anweisungen können explizit gemacht werden diff --git a/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.es.xlf b/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.es.xlf index a828ee4730b1d..f8f920679f207 100644 --- a/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.es.xlf +++ b/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.es.xlf @@ -2,11 +2,6 @@ - - Namespace can not be added in this destination. - El espacio de nombres no se puede agregar en este destino. - - Only attributes, expressions or statements can be made explicit Solo atributos, expresiones o instrucciones pueden hacerse explícitos diff --git a/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.fr.xlf b/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.fr.xlf index 104e111a3c795..cba9986390434 100644 --- a/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.fr.xlf +++ b/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.fr.xlf @@ -2,11 +2,6 @@ - - Namespace can not be added in this destination. - L'espace de noms ne peut pas être ajouté dans cette destination. - - Only attributes, expressions or statements can be made explicit Seuls les attributs, les expressions ou les déclarations peuvent être rendus explicites diff --git a/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.it.xlf b/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.it.xlf index 23926ea56983d..0668a338c5f4e 100644 --- a/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.it.xlf +++ b/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.it.xlf @@ -2,11 +2,6 @@ - - Namespace can not be added in this destination. - Non è possibile aggiungere lo spazio dei nomi in questa destinazione. - - Only attributes, expressions or statements can be made explicit È possibile rendere espliciti solo attributi, espressioni o istruzioni diff --git a/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.ja.xlf b/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.ja.xlf index 01aa95869062d..5924be0c13286 100644 --- a/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.ja.xlf +++ b/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.ja.xlf @@ -2,11 +2,6 @@ - - Namespace can not be added in this destination. - 名前空間は、このターゲットでは追加できません。 - - Only attributes, expressions or statements can be made explicit 属性、式、またはステートメントのみを明示的にすることができます diff --git a/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.ko.xlf b/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.ko.xlf index 8f7664f22d652..cc645230fa24d 100644 --- a/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.ko.xlf +++ b/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.ko.xlf @@ -2,11 +2,6 @@ - - Namespace can not be added in this destination. - 이 대상에는 네임스페이스를 추가할 수 없습니다. - - Only attributes, expressions or statements can be made explicit 특성, 식 또는 문만 명시적일 수 있습니다. diff --git a/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.pl.xlf b/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.pl.xlf index 13b56c6a55309..70bdac61bff28 100644 --- a/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.pl.xlf +++ b/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.pl.xlf @@ -2,11 +2,6 @@ - - Namespace can not be added in this destination. - Do tego miejsca docelowego nie można dodać przestrzeni nazw. - - Only attributes, expressions or statements can be made explicit Jako jawne można ustawić tylko atrybuty, wyrażenia lub instrukcje diff --git a/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.pt-BR.xlf b/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.pt-BR.xlf index 8ee104e3ab603..07d03ccdfcdf8 100644 --- a/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.pt-BR.xlf +++ b/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.pt-BR.xlf @@ -2,11 +2,6 @@ - - Namespace can not be added in this destination. - Namespace não pode ser adicionado nesse destino. - - Only attributes, expressions or statements can be made explicit Somente atributos, expressões ou instruções podem ser tornados explícitos diff --git a/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.ru.xlf b/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.ru.xlf index 1b577679dc3f9..79fca3c4d8de2 100644 --- a/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.ru.xlf +++ b/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.ru.xlf @@ -2,11 +2,6 @@ - - Namespace can not be added in this destination. - Не удается добавить пространство имен в этот конечный объект. - - Only attributes, expressions or statements can be made explicit Явными могут стать только атрибуты, выражения или операторы diff --git a/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.tr.xlf b/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.tr.xlf index aac21f16029bd..e257b03cd0866 100644 --- a/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.tr.xlf +++ b/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.tr.xlf @@ -2,11 +2,6 @@ - - Namespace can not be added in this destination. - Ad alanı bu hedefe eklenemez. - - Only attributes, expressions or statements can be made explicit Yalnızca öznitelikler, ifadeler veya deyimler açık hale getirilebilir diff --git a/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.zh-Hans.xlf b/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.zh-Hans.xlf index 1fd78caf06402..2227c1d84eb5e 100644 --- a/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.zh-Hans.xlf +++ b/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.zh-Hans.xlf @@ -2,11 +2,6 @@ - - Namespace can not be added in this destination. - 不能在此目标中添加命名空间。 - - Only attributes, expressions or statements can be made explicit 只有属性、表达式或语句可以变得明显 diff --git a/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.zh-Hant.xlf b/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.zh-Hant.xlf index 44960fcd0ace1..458c31aa88bbc 100644 --- a/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.zh-Hant.xlf +++ b/src/Workspaces/VisualBasic/Portable/xlf/VBWorkspaceResources.zh-Hant.xlf @@ -2,11 +2,6 @@ - - Namespace can not be added in this destination. - 無法將命名空間加入此目的地。 - - Only attributes, expressions or statements can be made explicit 只有屬性、運算式或陳述式可以設為明確