From 1b4ef7a1f5d6982169a5c5a0e914a26eb92a3c40 Mon Sep 17 00:00:00 2001 From: CyrusNajmabadi Date: Tue, 21 Jun 2016 17:03:51 -0700 Subject: [PATCH] Don't trim using namespaces. --- .../Diagnostics/AddUsing/AddUsingTests.cs | 169 ++++++++- .../AddUsing/AddUsingTests_Queries.cs | 2 - .../TypeInferrer/TypeInferrerTests.cs | 246 ++++++------ .../LambdaParameterExpansionTests.vb | 9 +- .../CSharpAddImportCodeFixProvider.cs | 350 ++++++++++++------ ...tCodeFixProvider.ProjectSymbolReference.cs | 9 +- ...ddImportCodeFixProvider.SymbolReference.cs | 7 +- .../AbstractAddImportCodeFixProvider.cs | 2 +- .../VisualBasicAddImportCodeFixProvider.vb | 7 +- .../Extensions/ExpressionSyntaxExtensions.cs | 52 ++- ...nsions.ExpressionSyntaxGeneratorVisitor.cs | 4 +- ...olExtensions.TypeSyntaxGeneratorVisitor.cs | 152 ++++---- .../Extensions/ITypeSymbolExtensions.cs | 19 +- .../Extensions/SyntaxNodeExtensions.cs | 8 + .../Portable/Utilities/NameSyntaxComparer.cs | 3 - .../CodeGeneration/SymbolEditorTests.cs | 2 +- .../CodeGeneration/SyntaxGeneratorTests.cs | 58 +-- .../CoreTest/Editting/SyntaxEditorTests.cs | 2 +- 18 files changed, 713 insertions(+), 388 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/AddUsing/AddUsingTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/AddUsing/AddUsingTests.cs index 1622c52055f..c719a8f2b3b 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/AddUsing/AddUsingTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/AddUsing/AddUsingTests.cs @@ -337,8 +337,31 @@ public async Task TestMultiplePresortedUsings1() public async Task TestMultiplePresortedUsings2() { await TestAsync( -@"using B.X; using B.Y; class Class { void Method() { [|Foo|].Bar(); } } namespace B.A { class Foo { public static void Bar() { } } }", -@"using B.A; using B.X; using B.Y; class Class { void Method() { Foo.Bar(); } } namespace B.A { class Foo { public static void Bar() { } } }"); +@"using B.X; +using B.Y; +class Class { + void Method() { + [|Foo|].Bar(); + } +} +namespace B.A { + class Foo { + public static void Bar() { } + } +}", +@"using B.A; +using B.X; +using B.Y; +class Class { + void Method() { + Foo.Bar(); + } +} +namespace B.A { + class Foo { + public static void Bar() { } + } +}"); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddUsing)] @@ -1453,8 +1476,27 @@ public async Task TestAddInsideUsingDirective4() public async Task TestAddInsideUsingDirective5() { await TestAsync( -@"using System.IO; namespace ns2 { using System.Diagnostics; namespace ns3 { using System.Collections; namespace ns { using B = [|Byte|]; } } }", -@"using System.IO; namespace ns2 { using System.Diagnostics; namespace ns3 { using System; using System.Collections; namespace ns { using B = Byte; } } }"); +@"using System.IO; +namespace ns2 { + using System.Diagnostics; + namespace ns3 { + using System.Collections; + namespace ns { + using B = [|Byte|]; + } + } +}", +@"using System.IO; +namespace ns2 { + using System.Diagnostics; + namespace ns3 { + using System; + using System.Collections; + namespace ns { + using B = Byte; + } + } +}"); } [WorkItem(991463, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/991463")] @@ -1562,8 +1604,35 @@ public class E public async Task TestAmbiguousUsingName() { await TestAsync( -@"namespace ClassLibrary1 { using System ; public class SomeTypeUser { [|SomeType|] field ; } } namespace SubNamespaceName { using System ; class SomeType { } } namespace ClassLibrary1 . SubNamespaceName { using System ; class SomeOtherFile { } } ", -@"namespace ClassLibrary1 { using System ; using global::SubNamespaceName ; public class SomeTypeUser { SomeType field ; } } namespace SubNamespaceName { using System ; class SomeType { } } namespace ClassLibrary1 . SubNamespaceName { using System ; class SomeOtherFile { } } "); +@"namespace ClassLibrary1 { + using System ; + public class SomeTypeUser { + [|SomeType|] field ; + } +} +namespace SubNamespaceName { + using System ; + class SomeType { } +} +namespace ClassLibrary1 . SubNamespaceName { + using System ; + class SomeOtherFile { } +} ", +@"namespace ClassLibrary1 { + using System ; + using global::SubNamespaceName ; + public class SomeTypeUser { + SomeType field ; + } +} +namespace SubNamespaceName { + using System ; + class SomeType { } +} +namespace ClassLibrary1 . SubNamespaceName { + using System ; + class SomeOtherFile { } +} "); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddUsing)] @@ -1745,7 +1814,7 @@ class T1 { } namespace A.C { using System; - using B; + using A.B; class T2 { void Test() @@ -1754,7 +1823,7 @@ void Test() T1 t1; } } -}"); +}", systemSpecialCase: true); } [WorkItem(935, "https://github.com/dotnet/roslyn/issues/935")] @@ -1798,8 +1867,23 @@ public async Task TestAddUsingWithOtherExtensionsInScope4() public async Task TestNestedNamespaceSimplified() { await TestAsync( -@"namespace Microsoft . MyApp { using Win32 ; class Program { static void Main ( string [ ] args ) { [|SafeRegistryHandle|] h ; } } } ", -@"namespace Microsoft . MyApp { using Win32 ; using Win32 . SafeHandles ; class Program { static void Main ( string [ ] args ) { SafeRegistryHandle h ; } } } "); +@"namespace Microsoft . MyApp { + using Win32 ; + class Program { + static void Main ( string [ ] args ) { + [|SafeRegistryHandle|] h ; + } + } +} ", +@"namespace Microsoft . MyApp { + using Microsoft.Win32 . SafeHandles ; + using Win32 ; + class Program { + static void Main ( string [ ] args ) { + SafeRegistryHandle h ; + } + } +} "); } [WorkItem(3080, "https://github.com/dotnet/roslyn/issues/3080")] @@ -1807,8 +1891,23 @@ public async Task TestNestedNamespaceSimplified() public async Task TestNestedNamespaceSimplified2() { await TestAsync( -@"namespace Microsoft . MyApp { using Zin32 ; class Program { static void Main ( string [ ] args ) { [|SafeRegistryHandle|] h ; } } } ", -@"namespace Microsoft . MyApp { using Win32 . SafeHandles ; using Zin32 ; class Program { static void Main ( string [ ] args ) { SafeRegistryHandle h ; } } } "); +@"namespace Microsoft . MyApp { + using Zin32 ; + class Program { + static void Main ( string [ ] args ) { + [|SafeRegistryHandle|] h ; + } + } +} ", +@"namespace Microsoft . MyApp { + using Microsoft . Win32 . SafeHandles ; + using Zin32 ; + class Program { + static void Main ( string [ ] args ) { + SafeRegistryHandle h ; + } + } +} "); } [WorkItem(3080, "https://github.com/dotnet/roslyn/issues/3080")] @@ -1816,8 +1915,25 @@ public async Task TestNestedNamespaceSimplified2() public async Task TestNestedNamespaceSimplified3() { await TestAsync( -@"namespace Microsoft . MyApp { using System ; using Win32 ; class Program { static void Main ( string [ ] args ) { [|SafeRegistryHandle|] h ; } } } ", -@"namespace Microsoft . MyApp { using System ; using Win32 ; using Win32 . SafeHandles ; class Program { static void Main ( string [ ] args ) { SafeRegistryHandle h ; } } } "); +@"namespace Microsoft . MyApp { + using System ; + using Win32 ; + class Program { + static void Main ( string [ ] args ) { + [|SafeRegistryHandle|] h ; + } + } +} ", +@"namespace Microsoft . MyApp { + using System ; + using Microsoft.Win32 . SafeHandles ; + using Win32 ; + class Program { + static void Main ( string [ ] args ) { + SafeRegistryHandle h ; + } + } +} "); } [WorkItem(3080, "https://github.com/dotnet/roslyn/issues/3080")] @@ -1825,8 +1941,25 @@ public async Task TestNestedNamespaceSimplified3() public async Task TestNestedNamespaceSimplified4() { await TestAsync( -@"namespace Microsoft . MyApp { using System ; using Zin32 ; class Program { static void Main ( string [ ] args ) { [|SafeRegistryHandle|] h ; } } } ", -@"namespace Microsoft . MyApp { using System ; using Win32 . SafeHandles ; using Zin32 ; class Program { static void Main ( string [ ] args ) { SafeRegistryHandle h ; } } } "); +@"namespace Microsoft . MyApp { + using System ; + using Zin32 ; + class Program { + static void Main ( string [ ] args ) { + [|SafeRegistryHandle|] h ; + } + } +} ", +@"namespace Microsoft . MyApp { + using System ; + using Microsoft . Win32 . SafeHandles ; + using Zin32 ; + class Program { + static void Main ( string [ ] args ) { + SafeRegistryHandle h ; + } + } +} "); } [WorkItem(3080, "https://github.com/dotnet/roslyn/issues/3080")] @@ -1852,8 +1985,8 @@ static void Main(string[] args) @"namespace Microsoft.MyApp { #if true + using Microsoft.Win32.SafeHandles; using Win32; - using Win32.SafeHandles; #else using System; #endif @@ -1890,11 +2023,11 @@ static void Main(string[] args) @"namespace Microsoft.MyApp { using System; + using Microsoft.Win32.SafeHandles; #if false using Win32; #endif using Win32; - using Win32.SafeHandles; class Program { static void Main(string[] args) diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/AddUsing/AddUsingTests_Queries.cs b/src/EditorFeatures/CSharpTest/Diagnostics/AddUsing/AddUsingTests_Queries.cs index 42ee49d66f6..167ee3b777b 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/AddUsing/AddUsingTests_Queries.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/AddUsing/AddUsingTests_Queries.cs @@ -1,8 +1,6 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; -using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; using Xunit; diff --git a/src/EditorFeatures/CSharpTest/TypeInferrer/TypeInferrerTests.cs b/src/EditorFeatures/CSharpTest/TypeInferrer/TypeInferrerTests.cs index 0fea5d4985f..40f4949536a 100644 --- a/src/EditorFeatures/CSharpTest/TypeInferrer/TypeInferrerTests.cs +++ b/src/EditorFeatures/CSharpTest/TypeInferrer/TypeInferrerTests.cs @@ -77,96 +77,96 @@ public async Task TestConditional1() { // We do not support position inference here as we're before the ? and we only look // backwards to infer a type here. - await TestInMethodAsync("var q = [|Foo()|] ? 1 : 2;", "System.Boolean", + await TestInMethodAsync("var q = [|Foo()|] ? 1 : 2;", "global::System.Boolean", testPosition: false); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestConditional2() { - await TestInMethodAsync("var q = a ? [|Foo()|] : 2;", "System.Int32"); + await TestInMethodAsync("var q = a ? [|Foo()|] : 2;", "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestConditional3() { - await TestInMethodAsync(@"var q = a ? """" : [|Foo()|];", "System.String"); + await TestInMethodAsync(@"var q = a ? """" : [|Foo()|];", "global::System.String"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestVariableDeclarator1() { - await TestInMethodAsync("int q = [|Foo()|];", "System.Int32"); + await TestInMethodAsync("int q = [|Foo()|];", "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestVariableDeclarator2() { - await TestInMethodAsync("var q = [|Foo()|];", "System.Object"); + await TestInMethodAsync("var q = [|Foo()|];", "global::System.Object"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestCoalesce1() { - await TestInMethodAsync("var q = [|Foo()|] ?? 1;", "System.Int32?", testPosition: false); + await TestInMethodAsync("var q = [|Foo()|] ?? 1;", "global::System.Int32?", testPosition: false); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestCoalesce2() { await TestInMethodAsync(@"bool? b; - var q = b ?? [|Foo()|];", "System.Boolean"); + var q = b ?? [|Foo()|];", "global::System.Boolean"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestCoalesce3() { await TestInMethodAsync(@"string s; - var q = s ?? [|Foo()|];", "System.String"); + var q = s ?? [|Foo()|];", "global::System.String"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestCoalesce4() { - await TestInMethodAsync("var q = [|Foo()|] ?? string.Empty;", "System.String", testPosition: false); + await TestInMethodAsync("var q = [|Foo()|] ?? string.Empty;", "global::System.String", testPosition: false); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestBinaryExpression1() { await TestInMethodAsync(@"string s; - var q = s + [|Foo()|];", "System.String"); + var q = s + [|Foo()|];", "global::System.String"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestBinaryExpression2() { await TestInMethodAsync(@"var s; - var q = s || [|Foo()|];", "System.Boolean"); + var q = s || [|Foo()|];", "global::System.Boolean"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestBinaryOperator1() { - await TestInMethodAsync(@"var q = x << [|Foo()|];", "System.Int32"); + await TestInMethodAsync(@"var q = x << [|Foo()|];", "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestBinaryOperator2() { - await TestInMethodAsync(@"var q = x >> [|Foo()|];", "System.Int32"); + await TestInMethodAsync(@"var q = x >> [|Foo()|];", "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestAssignmentOperator3() { - await TestInMethodAsync(@"var q <<= [|Foo()|];", "System.Int32"); + await TestInMethodAsync(@"var q <<= [|Foo()|];", "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestAssignmentOperator4() { - await TestInMethodAsync(@"var q >>= [|Foo()|];", "System.Int32"); + await TestInMethodAsync(@"var q >>= [|Foo()|];", "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -184,7 +184,7 @@ static void Main(string[] args) { var c = new C() && [|Foo()|]; } -}", "System.Boolean"); +}", "global::System.Boolean"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -199,7 +199,7 @@ static void Main(string[] args) var x = a || [|7|]; } }"; - await TestAsync(text, "System.Boolean"); + await TestAsync(text, "global::System.Boolean"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -214,7 +214,7 @@ static void Main(string[] args) var x = a && [|7|]; } }"; - await TestAsync(text, "System.Boolean"); + await TestAsync(text, "global::System.Boolean"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -229,7 +229,7 @@ static void Main(string[] args) var x = [|a|] | true; } }"; - await TestAsync(text, "System.Boolean", testPosition: false); + await TestAsync(text, "global::System.Boolean", testPosition: false); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -244,7 +244,7 @@ static void Main(string[] args) var x = [|a|] | b | c || d; } }"; - await TestAsync(text, "System.Boolean", testPosition: false); + await TestAsync(text, "global::System.Boolean", testPosition: false); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -259,7 +259,7 @@ static void Main(string[] args) var x = a | b | [|c|] || d; } }"; - await TestAsync(text, "System.Boolean"); + await TestAsync(text, "global::System.Boolean"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -297,7 +297,7 @@ static object Foo(bool p) return p; } }"; - await TestAsync(text, "System.Boolean"); + await TestAsync(text, "global::System.Boolean"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -312,7 +312,7 @@ static void Main(string[] args) if (([|x|] | y) != 0) {} } }"; - await TestAsync(text, "System.Int32", testPosition: false); + await TestAsync(text, "global::System.Int32", testPosition: false); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -327,7 +327,7 @@ static void Main(string[] args) if ([|x|] | y) {} } }"; - await TestAsync(text, "System.Boolean"); + await TestAsync(text, "global::System.Boolean"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -342,7 +342,7 @@ static void Main(string[] args) var x = [|a|] & true; } }"; - await TestAsync(text, "System.Boolean", testPosition: false); + await TestAsync(text, "global::System.Boolean", testPosition: false); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -357,7 +357,7 @@ static void Main(string[] args) var x = [|a|] & b & c && d; } }"; - await TestAsync(text, "System.Boolean", testPosition: false); + await TestAsync(text, "global::System.Boolean", testPosition: false); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -372,7 +372,7 @@ static void Main(string[] args) var x = a & b & [|c|] && d; } }"; - await TestAsync(text, "System.Boolean"); + await TestAsync(text, "global::System.Boolean"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -410,7 +410,7 @@ static object Foo(bool p) return p; } }"; - await TestAsync(text, "System.Boolean"); + await TestAsync(text, "global::System.Boolean"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -425,7 +425,7 @@ static void Main(string[] args) if (([|x|] & y) != 0) {} } }"; - await TestAsync(text, "System.Int32", testPosition: false); + await TestAsync(text, "global::System.Int32", testPosition: false); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -440,7 +440,7 @@ static void Main(string[] args) if ([|x|] & y) {} } }"; - await TestAsync(text, "System.Boolean"); + await TestAsync(text, "global::System.Boolean"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -455,7 +455,7 @@ static void Main(string[] args) var x = [|a|] ^ true; } }"; - await TestAsync(text, "System.Boolean", testPosition: false); + await TestAsync(text, "global::System.Boolean", testPosition: false); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -470,7 +470,7 @@ static void Main(string[] args) var x = [|a|] ^ b ^ c && d; } }"; - await TestAsync(text, "System.Boolean", testPosition: false); + await TestAsync(text, "global::System.Boolean", testPosition: false); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -485,7 +485,7 @@ static void Main(string[] args) var x = a ^ b ^ [|c|] && d; } }"; - await TestAsync(text, "System.Boolean"); + await TestAsync(text, "global::System.Boolean"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -523,7 +523,7 @@ static object Foo(bool p) return p; } }"; - await TestAsync(text, "System.Boolean"); + await TestAsync(text, "global::System.Boolean"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -538,7 +538,7 @@ static void Main(string[] args) if (([|x|] ^ y) != 0) {} } }"; - await TestAsync(text, "System.Int32", testPosition: false); + await TestAsync(text, "global::System.Int32", testPosition: false); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -553,7 +553,7 @@ static void Main(string[] args) if ([|x|] ^ y) {} } }"; - await TestAsync(text, "System.Boolean"); + await TestAsync(text, "global::System.Boolean"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -568,7 +568,7 @@ static void Main(string[] args) if ([|x|] |= y) {} } }"; - await TestAsync(text, "System.Boolean"); + await TestAsync(text, "global::System.Boolean"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -583,7 +583,7 @@ static void Main(string[] args) int z = [|x|] |= y; } }"; - await TestAsync(text, "System.Int32"); + await TestAsync(text, "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -598,7 +598,7 @@ static void Main(string[] args) if ([|x|] &= y) {} } }"; - await TestAsync(text, "System.Boolean"); + await TestAsync(text, "global::System.Boolean"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -613,7 +613,7 @@ static void Main(string[] args) int z = [|x|] &= y; } }"; - await TestAsync(text, "System.Int32"); + await TestAsync(text, "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -628,7 +628,7 @@ static void Main(string[] args) if ([|x|] ^= y) {} } }"; - await TestAsync(text, "System.Boolean"); + await TestAsync(text, "global::System.Boolean"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -643,13 +643,13 @@ static void Main(string[] args) int z = [|x|] ^= y; } }"; - await TestAsync(text, "System.Int32"); + await TestAsync(text, "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestReturn1() { - await TestInClassAsync(@"int M() { return [|Foo()|]; }", "System.Int32"); + await TestInClassAsync(@"int M() { return [|Foo()|]; }", "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -661,7 +661,7 @@ public async Task TestReturn2() [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestReturn3() { - await TestInClassAsync(@"int Property { get { return [|Foo()|]; } }", "System.Int32"); + await TestInClassAsync(@"int Property { get { return [|Foo()|]; } }", "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -678,19 +678,19 @@ IEnumerable M() yield return [|abc|] } }"; - await TestAsync(markup, "System.Int32"); + await TestAsync(markup, "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestReturnInLambda() { - await TestInMethodAsync("System.Func f = s => { return [|Foo()|]; };", "System.Int32"); + await TestInMethodAsync("System.Func f = s => { return [|Foo()|]; };", "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestLambda() { - await TestInMethodAsync("System.Func f = s => [|Foo()|];", "System.Int32"); + await TestInMethodAsync("System.Func f = s => [|Foo()|];", "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -708,37 +708,37 @@ public async Task TestCatch() [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestIf() { - await TestInMethodAsync(@"if ([|Foo()|]) { }", "System.Boolean"); + await TestInMethodAsync(@"if ([|Foo()|]) { }", "global::System.Boolean"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestWhile() { - await TestInMethodAsync(@"while ([|Foo()|]) { }", "System.Boolean"); + await TestInMethodAsync(@"while ([|Foo()|]) { }", "global::System.Boolean"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestDo() { - await TestInMethodAsync(@"do { } while ([|Foo()|])", "System.Boolean"); + await TestInMethodAsync(@"do { } while ([|Foo()|])", "global::System.Boolean"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestFor1() { - await TestInMethodAsync(@"for (int i = 0; [|Foo()|]; i++) { }", "System.Boolean"); + await TestInMethodAsync(@"for (int i = 0; [|Foo()|]; i++) { }", "global::System.Boolean"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestFor2() { - await TestInMethodAsync(@"for (string i = [|Foo()|]; ; ) { }", "System.String"); + await TestInMethodAsync(@"for (string i = [|Foo()|]; ; ) { }", "global::System.String"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestFor3() { - await TestInMethodAsync(@"for (var i = [|Foo()|]; ; ) { }", "System.Int32"); + await TestInMethodAsync(@"for (var i = [|Foo()|]; ; ) { }", "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -750,7 +750,7 @@ public async Task TestUsing1() [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestUsing2() { - await TestInMethodAsync(@"using (int i = [|Foo()|]) { }", "System.Int32"); + await TestInMethodAsync(@"using (int i = [|Foo()|]) { }", "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -762,31 +762,31 @@ public async Task TestUsing3() [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestForEach() { - await TestInMethodAsync(@"foreach (int v in [|Foo()|]) { }", "global::System.Collections.Generic.IEnumerable"); + await TestInMethodAsync(@"foreach (int v in [|Foo()|]) { }", "global::System.Collections.Generic.IEnumerable"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestPrefixExpression1() { - await TestInMethodAsync(@"var q = +[|Foo()|];", "System.Int32"); + await TestInMethodAsync(@"var q = +[|Foo()|];", "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestPrefixExpression2() { - await TestInMethodAsync(@"var q = -[|Foo()|];", "System.Int32"); + await TestInMethodAsync(@"var q = -[|Foo()|];", "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestPrefixExpression3() { - await TestInMethodAsync(@"var q = ~[|Foo()|];", "System.Int32"); + await TestInMethodAsync(@"var q = ~[|Foo()|];", "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestPrefixExpression4() { - await TestInMethodAsync(@"var q = ![|Foo()|];", "System.Boolean"); + await TestInMethodAsync(@"var q = ![|Foo()|];", "global::System.Boolean"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -798,138 +798,138 @@ public async Task TestPrefixExpression5() [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestArrayRankSpecifier() { - await TestInMethodAsync(@"var q = new string[[|Foo()|]];", "System.Int32"); + await TestInMethodAsync(@"var q = new string[[|Foo()|]];", "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestSwitch1() { - await TestInMethodAsync(@"switch ([|Foo()|]) { }", "System.Int32"); + await TestInMethodAsync(@"switch ([|Foo()|]) { }", "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestSwitch2() { - await TestInMethodAsync(@"switch ([|Foo()|]) { default: }", "System.Int32"); + await TestInMethodAsync(@"switch ([|Foo()|]) { default: }", "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestSwitch3() { - await TestInMethodAsync(@"switch ([|Foo()|]) { case ""a"": }", "System.String"); + await TestInMethodAsync(@"switch ([|Foo()|]) { case ""a"": }", "global::System.String"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestMethodCall1() { - await TestInMethodAsync(@"Bar([|Foo()|]);", "System.Object"); + await TestInMethodAsync(@"Bar([|Foo()|]);", "global::System.Object"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestMethodCall2() { - await TestInClassAsync(@"void M() { Bar([|Foo()|]); } void Bar(int i);", "System.Int32"); + await TestInClassAsync(@"void M() { Bar([|Foo()|]); } void Bar(int i);", "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestMethodCall3() { - await TestInClassAsync(@"void M() { Bar([|Foo()|]); } void Bar();", "System.Object"); + await TestInClassAsync(@"void M() { Bar([|Foo()|]); } void Bar();", "global::System.Object"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestMethodCall4() { - await TestInClassAsync(@"void M() { Bar([|Foo()|]); } void Bar(int i, string s);", "System.Int32"); + await TestInClassAsync(@"void M() { Bar([|Foo()|]); } void Bar(int i, string s);", "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestMethodCall5() { - await TestInClassAsync(@"void M() { Bar(s: [|Foo()|]); } void Bar(int i, string s);", "System.String"); + await TestInClassAsync(@"void M() { Bar(s: [|Foo()|]); } void Bar(int i, string s);", "global::System.String"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestConstructorCall1() { - await TestInMethodAsync(@"new C([|Foo()|]);", "System.Object"); + await TestInMethodAsync(@"new C([|Foo()|]);", "global::System.Object"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestConstructorCall2() { - await TestInClassAsync(@"void M() { new C([|Foo()|]); } C(int i) { }", "System.Int32"); + await TestInClassAsync(@"void M() { new C([|Foo()|]); } C(int i) { }", "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestConstructorCall3() { - await TestInClassAsync(@"void M() { new C([|Foo()|]); } C() { }", "System.Object"); + await TestInClassAsync(@"void M() { new C([|Foo()|]); } C() { }", "global::System.Object"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestConstructorCall4() { - await TestInClassAsync(@"void M() { new C([|Foo()|]); } C(int i, string s) { }", "System.Int32"); + await TestInClassAsync(@"void M() { new C([|Foo()|]); } C(int i, string s) { }", "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestConstructorCall5() { - await TestInClassAsync(@"void M() { new C(s: [|Foo()|]); } C(int i, string s) { }", "System.String"); + await TestInClassAsync(@"void M() { new C(s: [|Foo()|]); } C(int i, string s) { }", "global::System.String"); } [WorkItem(858112, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/858112")] [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestThisConstructorInitializer1() { - await TestAsync(@"class MyClass { public MyClass(int x) : this([|test|]) { } }", "System.Int32"); + await TestAsync(@"class MyClass { public MyClass(int x) : this([|test|]) { } }", "global::System.Int32"); } [WorkItem(858112, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/858112")] [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestThisConstructorInitializer2() { - await TestAsync(@"class MyClass { public MyClass(int x, string y) : this(5, [|test|]) { } }", "System.String"); + await TestAsync(@"class MyClass { public MyClass(int x, string y) : this(5, [|test|]) { } }", "global::System.String"); } [WorkItem(858112, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/858112")] [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestBaseConstructorInitializer() { - await TestAsync(@"class B { public B(int x) { } } class D : B { public D() : base([|test|]) { } }", "System.Int32"); + await TestAsync(@"class B { public B(int x) { } } class D : B { public D() : base([|test|]) { } }", "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestIndexAccess1() { - await TestInMethodAsync(@"string[] i; i[[|Foo()|]];", "System.Int32"); + await TestInMethodAsync(@"string[] i; i[[|Foo()|]];", "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestIndexerCall1() { - await TestInMethodAsync(@"this[[|Foo()|]];", "System.Int32"); + await TestInMethodAsync(@"this[[|Foo()|]];", "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestIndexerCall2() { // Update this when binding of indexers is working. - await TestInClassAsync(@"void M() { this[[|Foo()|]]; } int this [int i] { get; }", "System.Int32"); + await TestInClassAsync(@"void M() { this[[|Foo()|]]; } int this [int i] { get; }", "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestIndexerCall3() { // Update this when binding of indexers is working. - await TestInClassAsync(@"void M() { this[[|Foo()|]]; } int this [int i, string s] { get; }", "System.Int32"); + await TestInClassAsync(@"void M() { this[[|Foo()|]]; } int this [int i, string s] { get; }", "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] public async Task TestIndexerCall5() { - await TestInClassAsync(@"void M() { this[s: [|Foo()|]]; } int this [int i, string s] { get; }", "System.String"); + await TestInClassAsync(@"void M() { this[s: [|Foo()|]]; } int this [int i, string s] { get; }", "global::System.String"); } [Fact] @@ -946,7 +946,7 @@ void M() } }"; - await TestAsync(text, "System.Int32"); + await TestAsync(text, "global::System.Int32"); } [Fact] @@ -966,7 +966,7 @@ void M() int Foo() { return 2; } }"; - await TestAsync(text, "System.Int32"); + await TestAsync(text, "global::System.Int32"); } [Fact] @@ -985,7 +985,7 @@ void M() int Bar() { return 1; } }"; - await TestAsync(text, "System.Int32"); + await TestAsync(text, "global::System.Int32"); } [Fact] @@ -1002,7 +1002,7 @@ void M() } }"; - await TestAsync(text, "System.Object"); + await TestAsync(text, "global::System.Object"); } [Fact] @@ -1019,7 +1019,7 @@ void M() } }"; - await TestAsync(text, "System.Int32"); + await TestAsync(text, "global::System.Int32"); } [Fact] @@ -1038,7 +1038,7 @@ void M() int Bar() { return 1; } }"; - await TestAsync(text, "System.Int32"); + await TestAsync(text, "global::System.Int32"); } [Fact] @@ -1057,7 +1057,7 @@ void M() } }"; - await TestAsync(text, "System.Int32"); + await TestAsync(text, "global::System.Int32"); } [Fact] @@ -1077,7 +1077,7 @@ void M() } }"; - await TestAsync(text, "System.Int32"); + await TestAsync(text, "global::System.Int32"); } [Fact] @@ -1097,7 +1097,7 @@ void M() } }"; - await TestAsync(text, "System.String"); + await TestAsync(text, "global::System.String"); } [Fact] @@ -1122,7 +1122,7 @@ public System.Collections.IEnumerator GetEnumerator() } }"; - await TestAsync(text, "System.Int32", testPosition: false); + await TestAsync(text, "global::System.Int32", testPosition: false); } [Fact] @@ -1147,7 +1147,7 @@ public System.Collections.IEnumerator GetEnumerator() } }"; - await TestAsync(text, "System.Boolean"); + await TestAsync(text, "global::System.Boolean"); } [Fact] @@ -1172,7 +1172,7 @@ public System.Collections.IEnumerator GetEnumerator() } }"; - await TestAsync(text, "System.String"); + await TestAsync(text, "global::System.String"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -1285,7 +1285,7 @@ void Foo() } }"; - await TestAsync(text, "global::System.Func"); + await TestAsync(text, "global::System.Func"); } [WorkItem(538993, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/538993")] @@ -1302,7 +1302,7 @@ void M() } }"; - await TestAsync(text, "System.Int32"); + await TestAsync(text, "global::System.Int32"); } [WorkItem(539813, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539813")] @@ -1318,7 +1318,7 @@ void M(int* i) } }"; - await TestAsync(text, "System.Int32"); + await TestAsync(text, "global::System.Int32"); } [WorkItem(539813, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539813")] @@ -1334,7 +1334,7 @@ void M(dynamic i) } }"; - await TestAsync(text, "System.Int32"); + await TestAsync(text, "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -1349,7 +1349,7 @@ void M() } }"; - await TestAsync(text, "System.String"); + await TestAsync(text, "global::System.String"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -1366,7 +1366,7 @@ void M() } }"; - await TestAsync(text, "global::System.Threading.Tasks.Task"); + await TestAsync(text, "global::System.Threading.Tasks.Task"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -1383,7 +1383,7 @@ void M() } }"; - await TestAsync(text, "global::System.Threading.Tasks.Task>"); + await TestAsync(text, "global::System.Threading.Tasks.Task>"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -1418,7 +1418,7 @@ void M() } }"; - await TestAsync(text, "System.Object"); + await TestAsync(text, "global::System.Object"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -1436,7 +1436,7 @@ async void M() } }"; - await TestAsync(text, "global::System.Threading.Tasks.Task"); + await TestAsync(text, "global::System.Threading.Tasks.Task"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -1453,7 +1453,7 @@ async Task M() return [|ab|] } }"; - await TestAsync(markup, "System.Int32"); + await TestAsync(markup, "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -1491,7 +1491,7 @@ public AAttribute(System.DayOfWeek a, double b) } }"; - await TestAsync(markup, "System.Double"); + await TestAsync(markup, "global::System.Double"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -1510,7 +1510,7 @@ public AAttribute(System.DayOfWeek a, double b) } }"; - await TestAsync(markup, "System.String"); + await TestAsync(markup, "global::System.String"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -1534,7 +1534,7 @@ private static void B(A a) } }"; - await TestAsync(text, "System.String"); + await TestAsync(text, "global::System.String"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -1547,7 +1547,7 @@ public async Task TestCatchFilterClause() { } catch (Exception) if ([|M()|]) }"; - await TestInMethodAsync(text, "System.Boolean"); + await TestInMethodAsync(text, "global::System.Boolean"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -1560,7 +1560,7 @@ public async Task TestCatchFilterClause1() { } catch (Exception) if ([|M|]) }"; - await TestInMethodAsync(text, "System.Boolean"); + await TestInMethodAsync(text, "global::System.Boolean"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -1573,7 +1573,7 @@ public async Task TestCatchFilterClause2() { } catch (Exception) if ([|M|].N) }"; - await TestInMethodAsync(text, "System.Object", testPosition: false); + await TestInMethodAsync(text, "global::System.Object", testPosition: false); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -1591,7 +1591,7 @@ static async void T() bool x = await [|M()|].ConfigureAwait(false); } }"; - await TestAsync(text, "global::System.Threading.Tasks.Task", testPosition: false); + await TestAsync(text, "global::System.Threading.Tasks.Task", testPosition: false); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -1609,7 +1609,7 @@ static async void T() bool x = await [|M|].ContinueWith(a => { return true; }).ContinueWith(a => { return false; }); } }"; - await TestAsync(text, "global::System.Threading.Tasks.Task", testPosition: false); + await TestAsync(text, "global::System.Threading.Tasks.Task", testPosition: false); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -1628,7 +1628,7 @@ private async void M() private async Task X(T t) { return t; } }"; - await TestAsync(text, "System.Boolean", testPosition: false); + await TestAsync(text, "global::System.Boolean", testPosition: false); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -1647,7 +1647,7 @@ private async void M() private async Task X(T t) { return t; } }"; - await TestAsync(text, "System.Boolean"); + await TestAsync(text, "global::System.Boolean"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -1662,7 +1662,7 @@ void M() object z = [|a|]?? null; } }"; - await TestAsync(text, "System.Object"); + await TestAsync(text, "global::System.Object"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -1677,7 +1677,7 @@ void M() object z = [|a|] ?? b ?? c; } }"; - await TestAsync(text, "System.Object"); + await TestAsync(text, "global::System.Object"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -1692,7 +1692,7 @@ void M() object z = a ?? [|b|] ?? c; } }"; - await TestAsync(text, "System.Object"); + await TestAsync(text, "global::System.Object"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -1710,7 +1710,7 @@ void M(IEnumerable args) args = args.Select(a =>[||]) } }"; - await TestAsync(text, "System.Object", testPosition: false); + await TestAsync(text, "global::System.Object", testPosition: false); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -1728,7 +1728,7 @@ void M(IEnumerable args) args = args.Select(a =>[|b|]) } }"; - await TestAsync(text, "System.String", testPosition: false); + await TestAsync(text, "global::System.String", testPosition: false); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -1767,7 +1767,7 @@ public async void M() Func> t2 = async () => { return [|a|]; }; } }"; - await TestAsync(text, "System.Int32"); + await TestAsync(text, "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -1786,7 +1786,7 @@ public async void M() Func> t2 = async delegate () { return [|a|]; }; } }"; - await TestAsync(text, "System.Int32"); + await TestAsync(text, "global::System.Int32"); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -1832,7 +1832,7 @@ void Foo() [|ints|].Where(i => i > 10); } }"; - await TestAsync(text, "global::System.Collections.Generic.IEnumerable", testPosition: false); + await TestAsync(text, "global::System.Collections.Generic.IEnumerable", testPosition: false); } [Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)] @@ -1848,7 +1848,7 @@ void Foo() [|ints|].Where(i => null); } }"; - await TestAsync(text, "global::System.Collections.Generic.IEnumerable", testPosition: false); + await TestAsync(text, "global::System.Collections.Generic.IEnumerable", testPosition: false); } } -} +} \ No newline at end of file diff --git a/src/EditorFeatures/Test2/Expansion/LambdaParameterExpansionTests.vb b/src/EditorFeatures/Test2/Expansion/LambdaParameterExpansionTests.vb index 093c11bf926..2b2dc91dd43 100644 --- a/src/EditorFeatures/Test2/Expansion/LambdaParameterExpansionTests.vb +++ b/src/EditorFeatures/Test2/Expansion/LambdaParameterExpansionTests.vb @@ -64,7 +64,7 @@ class C { void M() { - Action a = (System.Int32 x) => { }; + Action a = (global::System.Int32 x) => { }; } } ]]> @@ -97,7 +97,7 @@ class C { void M() { - Action a = (System.Int32 x) => { }; + Action a = (global::System.Int32 x) => { }; } } ]]> @@ -130,7 +130,7 @@ class C { void M() { - Action a = (System.Int32 x, System.Int32 y) => { }; + Action a = (global::System.Int32 x, global::System.Int32 y) => { }; } } ]]> @@ -163,13 +163,12 @@ class C { void M() { - Action a = (System.Int32 x, System.Int32 y, System.Int32 z) => { }; + Action a = (global::System.Int32 x, global::System.Int32 y, global::System.Int32 z) => { }; } } ]]> Await TestAsync(input, expected, expandParameter:=True) End Function - End Class End Namespace \ No newline at end of file diff --git a/src/Features/CSharp/Portable/CodeFixes/AddImport/CSharpAddImportCodeFixProvider.cs b/src/Features/CSharp/Portable/CodeFixes/AddImport/CSharpAddImportCodeFixProvider.cs index ebcd25260cc..dc2b543555b 100644 --- a/src/Features/CSharp/Portable/CodeFixes/AddImport/CSharpAddImportCodeFixProvider.cs +++ b/src/Features/CSharp/Portable/CodeFixes/AddImport/CSharpAddImportCodeFixProvider.cs @@ -397,32 +397,55 @@ protected override string GetDescription(IReadOnlyList nameParts) return $"using { string.Join(".", nameParts) };"; } - protected override string GetDescription( - INamespaceOrTypeSymbol namespaceSymbol, SemanticModel semanticModel, SyntaxNode contextNode, bool checkForExistingUsing) + protected override string TryGetDescription( + INamespaceOrTypeSymbol namespaceOrTypeSymbol, + SemanticModel semanticModel, + SyntaxNode contextNode, bool checkForExistingUsing) { var root = GetCompilationUnitSyntaxNode(contextNode); - // No localization necessary - string externAliasString; - if (TryGetExternAliasString(namespaceSymbol, semanticModel, root, out externAliasString)) + // See if this is a reference to a type from a reference that has a specific alias + // associated with it. If that extern alias hasn't already been brought into scope + // then add that one. Note: TryGetExternAliasString will check if this extern already + // exists in this scope. + var externAlias = TryGetExternAliasDirective( + namespaceOrTypeSymbol, semanticModel, contextNode, + checkForExistingExternAlias: true); + if (externAlias != null) { - return $"extern alias {externAliasString};"; + return $"extern alias {externAlias.Identifier.ValueText};"; } - string namespaceString; - if (TryGetNamespaceString(namespaceSymbol, root, false, null, checkForExistingUsing, out namespaceString)) + var usingDirective = TryGetUsingDirective( + namespaceOrTypeSymbol, semanticModel, root, contextNode); + + if (usingDirective != null) { - return $"using {namespaceString};"; + var displayString = namespaceOrTypeSymbol.ToDisplayString(); + return namespaceOrTypeSymbol.IsKind(SymbolKind.Namespace) + ? $"using {displayString};" + : $"using static {displayString};"; } - string staticNamespaceString; - if (TryGetStaticNamespaceString(namespaceSymbol, root, false, null, out staticNamespaceString)) + return null; + } + + private bool HasExistingUsingDirective( + CompilationUnitSyntax root, + NamespaceDeclarationSyntax namespaceToAddTo, + UsingDirectiveSyntax usingDirective) + { + var usings = namespaceToAddTo?.Usings ?? root.Usings; + + foreach (var existingUsing in usings) { - return $"using static {staticNamespaceString};"; + if (SyntaxFactory.AreEquivalent(usingDirective, existingUsing)) + { + return true; + } } - // We can't find a string to show to the user, we should not show this codefix. - return null; + return false; } protected override async Task AddImportAsync( @@ -439,71 +462,68 @@ protected override string GetDescription(IReadOnlyList nameParts) private async Task AddImportWorkerAsync( Document document, CompilationUnitSyntax root, SyntaxNode contextNode, - INamespaceOrTypeSymbol namespaceOrTypeSymbol, bool placeSystemNamespaceFirst, CancellationToken cancellationToken) + INamespaceOrTypeSymbol namespaceOrTypeSymbol, + bool placeSystemNamespaceFirst, CancellationToken cancellationToken) { var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); - var simpleUsingDirective = GetUsingDirective(root, namespaceOrTypeSymbol, semanticModel, fullyQualify: false); - var externAliasUsingDirective = GetExternAliasUsingDirective(root, namespaceOrTypeSymbol, semanticModel); - - if (externAliasUsingDirective != null) - { - root = root.AddExterns( - externAliasUsingDirective - .WithAdditionalAnnotations(Formatter.Annotation)); - } - - if (simpleUsingDirective == null) - { - return root; - } - - // Because of the way usings can be nested inside of namespace declarations, - // we need to check if the usings must be fully qualified so as not to be - // ambiguous with the containing namespace. - if (UsingsAreContainedInNamespace(contextNode)) - { - // When we add usings we try and place them, as best we can, where the user - // wants them according to their settings. This means we can't just add the fully- - // qualified usings and expect the simplifier to take care of it, the usings have to be - // simplified before we attempt to add them to the document. - // You might be tempted to think that we could call - // AddUsings -> Simplifier -> SortUsings - // But this will clobber the users using settings without asking. Instead we create a new - // Document and check if our using can be simplified. Worst case we need to back out the - // fully qualified change and reapply with the simple name. - var fullyQualifiedUsingDirective = GetUsingDirective(root, namespaceOrTypeSymbol, semanticModel, fullyQualify: true); - var newRoot = root.AddUsingDirective( - fullyQualifiedUsingDirective, contextNode, placeSystemNamespaceFirst, - Formatter.Annotation); - var newUsing = newRoot - .DescendantNodes().OfType() - .Where(uds => uds.IsEquivalentTo(fullyQualifiedUsingDirective, topLevel: true)) - .Single(); - newRoot = newRoot.TrackNodes(newUsing); - var documentWithSyntaxRoot = document.WithSyntaxRoot(newRoot); - var simplifiedDocument = await Simplifier.ReduceAsync(documentWithSyntaxRoot, newUsing.Span, cancellationToken: cancellationToken).ConfigureAwait(false); - - newRoot = (CompilationUnitSyntax)await simplifiedDocument.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); - var simplifiedUsing = newRoot.GetCurrentNode(newUsing); - if (simplifiedUsing.Name.IsEquivalentTo(newUsing.Name, topLevel: true)) - { - // Not fully qualifying the using causes to refer to a different namespace so we need to keep it as is. - return (CompilationUnitSyntax)await documentWithSyntaxRoot.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); - } - else - { - // It does not matter if it is fully qualified or simple so lets return the simple name. - return root.AddUsingDirective( - simplifiedUsing.WithoutAnnotations(), contextNode, placeSystemNamespaceFirst, - Formatter.Annotation); - } + + var firstContainingNamespaceWithUsings = GetFirstContainingNamespaceWithUsings(contextNode); + var namespaceToUpdate = firstContainingNamespaceWithUsings; + + var externAliasDirective = TryGetExternAliasDirective( + namespaceOrTypeSymbol, semanticModel, contextNode, + checkForExistingExternAlias: true); + + var usingDirective = TryGetUsingDirective( + namespaceOrTypeSymbol, semanticModel, root, contextNode); + + if (externAliasDirective != null) + { + AddExterns(ref root, ref namespaceToUpdate, externAliasDirective); + } + + if (usingDirective != null) + { + AddUsingDirective(ref root, ref namespaceToUpdate, + placeSystemNamespaceFirst, usingDirective); + } + + return firstContainingNamespaceWithUsings != null + ? root.ReplaceNode(firstContainingNamespaceWithUsings, namespaceToUpdate) + : root; + } + + private void AddUsingDirective( + ref CompilationUnitSyntax root, + ref NamespaceDeclarationSyntax namespaceToUpdate, + bool placeSystemNamespaceFirst, + UsingDirectiveSyntax usingDirective) + { + IList directives = new[] { usingDirective }; + if (namespaceToUpdate != null) + { + namespaceToUpdate = namespaceToUpdate.AddUsingDirectives( + directives, placeSystemNamespaceFirst); } else { - // simple form - return root.AddUsingDirective( - simpleUsingDirective, contextNode, placeSystemNamespaceFirst, - Formatter.Annotation); + root = root.AddUsingDirectives( + directives, placeSystemNamespaceFirst); + } + } + + private void AddExterns( + ref CompilationUnitSyntax root, + ref NamespaceDeclarationSyntax namespaceToUpdate, + ExternAliasDirectiveSyntax externAliasDirective) + { + if (namespaceToUpdate != null) + { + namespaceToUpdate = namespaceToUpdate.AddExterns(externAliasDirective); + } + else + { + root = root.AddExterns(externAliasDirective); } } @@ -546,65 +566,149 @@ private NameSyntax CreateNameSyntax(IReadOnlyList namespaceParts, int in : SyntaxFactory.QualifiedName(CreateNameSyntax(namespaceParts, index - 1), namePiece); } - private static ExternAliasDirectiveSyntax GetExternAliasUsingDirective(CompilationUnitSyntax root, INamespaceOrTypeSymbol namespaceSymbol, SemanticModel semanticModel) + private static ExternAliasDirectiveSyntax TryGetExternAliasDirective( + INamespaceOrTypeSymbol namespaceSymbol, + SemanticModel semanticModel, + SyntaxNode contextNode, + bool checkForExistingExternAlias) { string externAliasString; - if (TryGetExternAliasString(namespaceSymbol, semanticModel, root, out externAliasString)) + if (TryGetExternAliasString(namespaceSymbol, semanticModel, contextNode, checkForExistingExternAlias, out externAliasString)) { - return SyntaxFactory.ExternAliasDirective(SyntaxFactory.Identifier(externAliasString)); + return SyntaxFactory.ExternAliasDirective(SyntaxFactory.Identifier(externAliasString)) + .WithAdditionalAnnotations(Formatter.Annotation); } return null; } - private UsingDirectiveSyntax GetUsingDirective(CompilationUnitSyntax root, INamespaceOrTypeSymbol namespaceSymbol, SemanticModel semanticModel, bool fullyQualify) + private UsingDirectiveSyntax TryGetUsingDirective( + INamespaceOrTypeSymbol namespaceOrTypeSymbol, + SemanticModel semanticModel, + CompilationUnitSyntax root, + SyntaxNode contextNode) { - if (namespaceSymbol is INamespaceSymbol) + var namespaceToAddTo = GetFirstContainingNamespaceWithUsings(contextNode); + var usingDirectives = namespaceToAddTo?.Usings ?? root.Usings; + + var nameSyntax = namespaceOrTypeSymbol.GenerateNameSyntax(); + + // Replace the alias that GenerateTypeSyntax added if we want this to be looked + // up off of an extern alias. + var externAliasDirective = TryGetExternAliasDirective( + namespaceOrTypeSymbol, semanticModel, contextNode, + checkForExistingExternAlias: false); + + var externAlias = externAliasDirective?.Identifier.ValueText; + if (externAlias != null) { - string namespaceString; - string externAliasString; - TryGetExternAliasString(namespaceSymbol, semanticModel, root, out externAliasString); - if (externAliasString != null) - { - if (TryGetNamespaceString(namespaceSymbol, root, false, externAliasString, - checkForExistingUsing: true, namespaceString: out namespaceString)) - { - return SyntaxFactory.UsingDirective(SyntaxFactory.ParseName(namespaceString).WithAdditionalAnnotations(Simplifier.Annotation)); - } + nameSyntax = AddOrReplaceAlias(nameSyntax, SyntaxFactory.IdentifierName(externAlias)); + } + else + { + // The name we generated will have the global:: alias on it. We only need + // that if the name of our symbol is actually ambiguous in this context. + // If so, keep global:: on it, otherwise remove it. + nameSyntax = RemoveGlobalAliasIfUnnecessary(semanticModel, nameSyntax, namespaceToAddTo); + } - return null; - } + var usingDirective = SyntaxFactory.UsingDirective(nameSyntax) + .WithAdditionalAnnotations(Formatter.Annotation); + + if (HasExistingUsingDirective(root, namespaceToAddTo, usingDirective)) + { + return null; + } - if (TryGetNamespaceString(namespaceSymbol, root, fullyQualify, null, - checkForExistingUsing: true, namespaceString: out namespaceString)) + return namespaceOrTypeSymbol.IsKind(SymbolKind.Namespace) + ? usingDirective + : usingDirective.WithStaticKeyword(SyntaxFactory.Token(SyntaxKind.StaticKeyword)); + } + + private NameSyntax RemoveGlobalAliasIfUnnecessary( + SemanticModel semanticModel, + NameSyntax nameSyntax, + NamespaceDeclarationSyntax namespaceToAddTo) + { + var aliasQualifiedName = nameSyntax.DescendantNodesAndSelf() + .OfType() + .FirstOrDefault(); + if (aliasQualifiedName != null) + { + var rightOfAliasName = aliasQualifiedName.Name.Identifier.ValueText; + if (!ConflictsWithExistingMember(semanticModel, namespaceToAddTo, rightOfAliasName)) { - return SyntaxFactory.UsingDirective(SyntaxFactory.ParseName(namespaceString).WithAdditionalAnnotations(Simplifier.Annotation)); + // Strip off the alias. + return nameSyntax.ReplaceNode(aliasQualifiedName, aliasQualifiedName.Name); } } - if (namespaceSymbol is ITypeSymbol) + return nameSyntax; + } + + private bool ConflictsWithExistingMember( + SemanticModel semanticModel, + NamespaceDeclarationSyntax namespaceToAddTo, + string rightOfAliasName) + { + if (namespaceToAddTo != null) { - string staticNamespaceString; - if (TryGetStaticNamespaceString(namespaceSymbol, root, fullyQualify, null, out staticNamespaceString)) + var containingNamespaceSymbol = semanticModel.GetDeclaredSymbol(namespaceToAddTo); + + while (containingNamespaceSymbol != null && !containingNamespaceSymbol.IsGlobalNamespace) { - return SyntaxFactory.UsingDirective( - SyntaxFactory.Token(SyntaxKind.UsingKeyword), - SyntaxFactory.Token(SyntaxKind.StaticKeyword), - null, - SyntaxFactory.ParseName(staticNamespaceString).WithAdditionalAnnotations(Simplifier.Annotation), - SyntaxFactory.Token(SyntaxKind.SemicolonToken)); + if (containingNamespaceSymbol.GetMembers(rightOfAliasName).Any()) + { + // A containing namespace had this name in it. We need to stay globally qualified. + return true; + } + + containingNamespaceSymbol = containingNamespaceSymbol.ContainingNamespace; } } - return null; + // Didn't conflict with anything. We shoudl remove the global:: alias. + return false; } - private bool UsingsAreContainedInNamespace(SyntaxNode contextNode) + private NameSyntax AddOrReplaceAlias( + NameSyntax nameSyntax, IdentifierNameSyntax alias) { - return contextNode.GetAncestor()?.DescendantNodes().OfType().FirstOrDefault() != null; + var simpleName = nameSyntax as SimpleNameSyntax; + if (simpleName != null) + { + return SyntaxFactory.AliasQualifiedName(alias, simpleName); + } + + var qualifiedName = nameSyntax as QualifiedNameSyntax; + if (qualifiedName != null) + { + return qualifiedName.WithLeft(AddOrReplaceAlias(qualifiedName.Left, alias)); + } + + var aliasName = nameSyntax as AliasQualifiedNameSyntax; + return aliasName.WithAlias(alias); } - private static bool TryGetExternAliasString(INamespaceOrTypeSymbol namespaceSymbol, SemanticModel semanticModel, CompilationUnitSyntax root, out string externAliasString) + private NamespaceDeclarationSyntax GetFirstContainingNamespaceWithUsings(SyntaxNode contextNode) + { + var usingDirective = contextNode.GetAncestor(); + if (usingDirective != null) + { + contextNode = usingDirective.Parent; + } + + return contextNode.GetAncestors() + .Where(n => n.Usings.Count > 0) + .FirstOrDefault(); + } + + private static bool TryGetExternAliasString( + INamespaceOrTypeSymbol namespaceSymbol, + SemanticModel semanticModel, + SyntaxNode contextNode, + bool checkForExistingExternAlias, + out string externAliasString) { externAliasString = null; var metadataReference = semanticModel.Compilation.GetMetadataReference(namespaceSymbol.ContainingAssembly); @@ -625,12 +729,13 @@ private static bool TryGetExternAliasString(INamespaceOrTypeSymbol namespaceSymb return false; } + // Just default to using the first alias we see for this symbol. externAliasString = aliases.First(); - return ShouldAddExternAlias(aliases, root); + return !checkForExistingExternAlias || ShouldAddExternAlias(externAliasString, contextNode); } private static bool TryGetNamespaceString( - INamespaceOrTypeSymbol namespaceSymbol, CompilationUnitSyntax root, bool fullyQualify, string alias, + INamespaceOrTypeSymbol namespaceSymbol, CompilationUnitSyntax root, string alias, bool checkForExistingUsing, out string namespaceString) { if (namespaceSymbol is ITypeSymbol) @@ -639,9 +744,7 @@ private static bool TryGetExternAliasString(INamespaceOrTypeSymbol namespaceSymb return false; } - namespaceString = fullyQualify - ? namespaceSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) - : namespaceSymbol.ToDisplayString(); + namespaceString = namespaceSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); if (alias != null) { @@ -653,7 +756,9 @@ private static bool TryGetExternAliasString(INamespaceOrTypeSymbol namespaceSymb : true; } - private static bool TryGetStaticNamespaceString(INamespaceOrTypeSymbol namespaceSymbol, CompilationUnitSyntax root, bool fullyQualify, string alias, out string namespaceString) + private static bool TryGetStaticNamespaceString( + INamespaceOrTypeSymbol namespaceSymbol, CompilationUnitSyntax root, + string alias, out string namespaceString) { if (namespaceSymbol is INamespaceSymbol) { @@ -661,9 +766,7 @@ private static bool TryGetStaticNamespaceString(INamespaceOrTypeSymbol namespace return false; } - namespaceString = fullyQualify - ? namespaceSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) - : namespaceSymbol.ToDisplayString(); + namespaceString = namespaceSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); if (alias != null) { @@ -673,11 +776,18 @@ private static bool TryGetStaticNamespaceString(INamespaceOrTypeSymbol namespace return ShouldAddStaticUsing(namespaceString, root); } - private static bool ShouldAddExternAlias(ImmutableArray aliases, CompilationUnitSyntax root) + private static bool ShouldAddExternAlias(string alias, SyntaxNode contextNode) { - var identifiers = root.DescendantNodes().OfType().Select(e => e.Identifier.ToString()); - var externAliases = aliases.Where(a => identifiers.Contains(a)); - return !externAliases.Any(); + foreach (var externAlias in contextNode.GetEnclosingExternAliasDirectives()) + { + // We already have this extern alias in scope. No need to add it. + if (externAlias.Identifier.ValueText == alias) + { + return false; + } + } + + return true; } private static bool ShouldAddUsing(string usingDirective, CompilationUnitSyntax root) diff --git a/src/Features/Core/Portable/CodeFixes/AddImport/AbstractAddImportCodeFixProvider.ProjectSymbolReference.cs b/src/Features/Core/Portable/CodeFixes/AddImport/AbstractAddImportCodeFixProvider.ProjectSymbolReference.cs index 460258b64b8..35468dd085e 100644 --- a/src/Features/Core/Portable/CodeFixes/AddImport/AbstractAddImportCodeFixProvider.ProjectSymbolReference.cs +++ b/src/Features/Core/Portable/CodeFixes/AddImport/AbstractAddImportCodeFixProvider.ProjectSymbolReference.cs @@ -89,9 +89,14 @@ protected override Solution UpdateSolution(Document newDocument) return newProject.Solution; } - protected override string GetDescription(Project project, SyntaxNode node, SemanticModel semanticModel) + protected override string TryGetDescription(Project project, SyntaxNode node, SemanticModel semanticModel) { - var description = base.GetDescription(project, node, semanticModel); + var description = base.TryGetDescription(project, node, semanticModel); + if (description == null) + { + return null; + } + return project.Id == _project.Id ? description : $"{description} ({string.Format(FeaturesResources.from_0, _project.Name)})"; diff --git a/src/Features/Core/Portable/CodeFixes/AddImport/AbstractAddImportCodeFixProvider.SymbolReference.cs b/src/Features/Core/Portable/CodeFixes/AddImport/AbstractAddImportCodeFixProvider.SymbolReference.cs index 840cf20c488..15f6047fe25 100644 --- a/src/Features/Core/Portable/CodeFixes/AddImport/AbstractAddImportCodeFixProvider.SymbolReference.cs +++ b/src/Features/Core/Portable/CodeFixes/AddImport/AbstractAddImportCodeFixProvider.SymbolReference.cs @@ -84,7 +84,7 @@ public override int GetHashCode() Document document, SyntaxNode node, bool placeSystemNamespaceFirst, CancellationToken cancellationToken) { var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); - string description = GetDescription(document.Project, node, semanticModel); + string description = TryGetDescription(document.Project, node, semanticModel); if (description == null) { return null; @@ -102,9 +102,10 @@ public override int GetHashCode() return null; } - protected virtual string GetDescription(Project project, SyntaxNode node, SemanticModel semanticModel) + protected virtual string TryGetDescription( + Project project, SyntaxNode node, SemanticModel semanticModel) { - return provider.GetDescription(SymbolResult.Symbol, semanticModel, node, this.CheckForExistingImport(project)); + return provider.TryGetDescription(SymbolResult.Symbol, semanticModel, node, this.CheckForExistingImport(project)); } } } diff --git a/src/Features/Core/Portable/CodeFixes/AddImport/AbstractAddImportCodeFixProvider.cs b/src/Features/Core/Portable/CodeFixes/AddImport/AbstractAddImportCodeFixProvider.cs index e4b04826711..8a26e5f002e 100644 --- a/src/Features/Core/Portable/CodeFixes/AddImport/AbstractAddImportCodeFixProvider.cs +++ b/src/Features/Core/Portable/CodeFixes/AddImport/AbstractAddImportCodeFixProvider.cs @@ -53,7 +53,7 @@ internal abstract partial class AbstractAddImportCodeFixProvider nameParts); - protected abstract string GetDescription(INamespaceOrTypeSymbol symbol, SemanticModel semanticModel, SyntaxNode root, bool checkForExistingImport); + protected abstract string TryGetDescription(INamespaceOrTypeSymbol symbol, SemanticModel semanticModel, SyntaxNode root, bool checkForExistingImport); public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { diff --git a/src/Features/VisualBasic/Portable/CodeFixes/AddImport/VisualBasicAddImportCodeFixProvider.vb b/src/Features/VisualBasic/Portable/CodeFixes/AddImport/VisualBasicAddImportCodeFixProvider.vb index d720f6b323a..27ff9b75f2f 100644 --- a/src/Features/VisualBasic/Portable/CodeFixes/AddImport/VisualBasicAddImportCodeFixProvider.vb +++ b/src/Features/VisualBasic/Portable/CodeFixes/AddImport/VisualBasicAddImportCodeFixProvider.vb @@ -247,8 +247,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.AddImport Return $"Imports { String.Join(".", nameParts) }" End Function - Protected Overrides Function GetDescription(namespaceSymbol As INamespaceOrTypeSymbol, semanticModel As SemanticModel, - root As SyntaxNode, checkForExistingImport As Boolean) As String + Protected Overrides Function TryGetDescription( + namespaceSymbol As INamespaceOrTypeSymbol, + semanticModel As SemanticModel, + root As SyntaxNode, + checkForExistingImport As Boolean) As String Return $"Imports {namespaceSymbol.ToDisplayString()}" End Function diff --git a/src/Workspaces/CSharp/Portable/Extensions/ExpressionSyntaxExtensions.cs b/src/Workspaces/CSharp/Portable/Extensions/ExpressionSyntaxExtensions.cs index 3b79ee8492d..40de3a94e54 100644 --- a/src/Workspaces/CSharp/Portable/Extensions/ExpressionSyntaxExtensions.cs +++ b/src/Workspaces/CSharp/Portable/Extensions/ExpressionSyntaxExtensions.cs @@ -1936,7 +1936,8 @@ private static bool CanReplaceWithReducedName(this NameSyntax name, TypeSyntax r return CanReplaceWithReducedNameInContext(name, reducedName, semanticModel, cancellationToken); } - private static bool CanReplaceWithReducedNameInContext(this NameSyntax name, TypeSyntax reducedName, SemanticModel semanticModel, CancellationToken cancellationToken) + private static bool CanReplaceWithReducedNameInContext( + this NameSyntax name, TypeSyntax reducedName, SemanticModel semanticModel, CancellationToken cancellationToken) { // Special case. if this new minimal name parses out to a predefined type, then we // have to make sure that we're not in a using alias. That's the one place where the @@ -1946,10 +1947,15 @@ private static bool CanReplaceWithReducedNameInContext(this NameSyntax name, Typ var invalidTransformation2 = WillConflictWithExistingLocal(name, reducedName); var invalidTransformation3 = IsAmbiguousCast(name, reducedName); var invalidTransformation4 = IsNullableTypeInPointerExpression(name, reducedName); - var isNotNullableReplaceable = name.IsNotNullableReplaceable(reducedName); + var invalidTransformation5 = name.IsNotNullableReplaceable(reducedName); + var invalidTransformation6 = IsQualifiedNameInUsingDirective(semanticModel, name, reducedName); - if (invalidTransformation1 || invalidTransformation2 || invalidTransformation3 || invalidTransformation4 - || isNotNullableReplaceable) + if (invalidTransformation1 || + invalidTransformation2 || + invalidTransformation3 || + invalidTransformation4 || + invalidTransformation5 || + invalidTransformation6) { return false; } @@ -1957,6 +1963,44 @@ private static bool CanReplaceWithReducedNameInContext(this NameSyntax name, Typ return true; } + private static bool IsQualifiedNameInUsingDirective(SemanticModel model, NameSyntax name, TypeSyntax reducedName) + { + while (name.IsLeftSideOfQualifiedName()) + { + name = (NameSyntax)name.Parent; + } + + if (name.IsParentKind(SyntaxKind.UsingDirective) && + ((UsingDirectiveSyntax)name.Parent).Alias == null) + { + // We're a qualified name in a using. We don't want to reduce this name as people like + // fully qualified names in usings so they can properly tell what the name is resolving + // to. + // However, if this name is actually referencing the special Script class, then we do + // want to allow that to be reduced. + + return !IsInScriptClass(model, name); + } + + return false; + } + + private static bool IsInScriptClass(SemanticModel model, NameSyntax name) + { + var symbol = model.GetSymbolInfo(name).Symbol as INamedTypeSymbol; + while (symbol != null) + { + if (symbol.IsScriptClass) + { + return true; + } + + symbol = symbol.ContainingType; + } + + return false; + } + private static bool IsNotNullableReplaceable(this NameSyntax name, TypeSyntax reducedName) { var isNotNullableReplaceable = false; diff --git a/src/Workspaces/CSharp/Portable/Extensions/ITypeSymbolExtensions.ExpressionSyntaxGeneratorVisitor.cs b/src/Workspaces/CSharp/Portable/Extensions/ITypeSymbolExtensions.ExpressionSyntaxGeneratorVisitor.cs index 9bea3616b7b..2c699378862 100644 --- a/src/Workspaces/CSharp/Portable/Extensions/ITypeSymbolExtensions.ExpressionSyntaxGeneratorVisitor.cs +++ b/src/Workspaces/CSharp/Portable/Extensions/ITypeSymbolExtensions.ExpressionSyntaxGeneratorVisitor.cs @@ -24,7 +24,7 @@ private ExpressionSyntaxGeneratorVisitor() public override ExpressionSyntax DefaultVisit(ISymbol symbol) { - return symbol.Accept(TypeSyntaxGeneratorVisitor.Instance); + return symbol.Accept(TypeSyntaxGeneratorVisitor.Create()); } private TExpressionSyntax AddInformationTo(TExpressionSyntax syntax, ISymbol symbol) @@ -38,7 +38,7 @@ private TExpressionSyntax AddInformationTo(TExpressionSyntax public override ExpressionSyntax VisitNamedType(INamedTypeSymbol symbol) { - var typeSyntax = TypeSyntaxGeneratorVisitor.Instance.CreateSimpleTypeSyntax(symbol); + var typeSyntax = TypeSyntaxGeneratorVisitor.Create().CreateSimpleTypeSyntax(symbol); if (!(typeSyntax is SimpleNameSyntax)) { return typeSyntax; diff --git a/src/Workspaces/CSharp/Portable/Extensions/ITypeSymbolExtensions.TypeSyntaxGeneratorVisitor.cs b/src/Workspaces/CSharp/Portable/Extensions/ITypeSymbolExtensions.TypeSyntaxGeneratorVisitor.cs index 8237ca81c64..9ff415dcfe7 100644 --- a/src/Workspaces/CSharp/Portable/Extensions/ITypeSymbolExtensions.TypeSyntaxGeneratorVisitor.cs +++ b/src/Workspaces/CSharp/Portable/Extensions/ITypeSymbolExtensions.TypeSyntaxGeneratorVisitor.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; -using System.Collections.Immutable; using System.Linq; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Shared.Extensions; @@ -14,10 +13,16 @@ internal partial class ITypeSymbolExtensions { private class TypeSyntaxGeneratorVisitor : SymbolVisitor { - public static readonly TypeSyntaxGeneratorVisitor Instance = new TypeSyntaxGeneratorVisitor(); + private readonly bool _nameOnly; - private TypeSyntaxGeneratorVisitor() + private TypeSyntaxGeneratorVisitor(bool nameOnly) { + _nameOnly = nameOnly; + } + + public static TypeSyntaxGeneratorVisitor Create(bool nameOnly = false) + { + return new TypeSyntaxGeneratorVisitor(nameOnly); } public override TypeSyntax DefaultVisit(ISymbol node) @@ -39,15 +44,25 @@ public override TypeSyntax VisitAlias(IAliasSymbol symbol) return AddInformationTo(symbol.Name.ToIdentifierName(), symbol); } + private void ThrowIfNameOnly() + { + if (_nameOnly) + { + throw new InvalidOperationException("This symbol cannot be converted into a NameSyntax"); + } + } + public override TypeSyntax VisitArrayType(IArrayTypeSymbol symbol) { + ThrowIfNameOnly(); + var underlyingNonArrayType = symbol.ElementType; while (underlyingNonArrayType.Kind == SymbolKind.ArrayType) { underlyingNonArrayType = ((IArrayTypeSymbol)underlyingNonArrayType).ElementType; } - var elementTypeSyntax = underlyingNonArrayType.Accept(this); + var elementTypeSyntax = underlyingNonArrayType.GenerateTypeSyntax(); var ranks = new List(); var arrayType = symbol; @@ -71,68 +86,25 @@ public override TypeSyntax VisitDynamicType(IDynamicTypeSymbol symbol) public TypeSyntax CreateSimpleTypeSyntax(INamedTypeSymbol symbol) { - switch (symbol.SpecialType) + if (!_nameOnly) { - case SpecialType.System_Object: - return SyntaxFactory.QualifiedName(SyntaxFactory.IdentifierName("System"), SyntaxFactory.IdentifierName("Object")); - case SpecialType.System_Void: - return SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.VoidKeyword)); - case SpecialType.System_Boolean: - return SyntaxFactory.QualifiedName(SyntaxFactory.IdentifierName("System"), SyntaxFactory.IdentifierName("Boolean")); - case SpecialType.System_Char: - return SyntaxFactory.QualifiedName(SyntaxFactory.IdentifierName("System"), SyntaxFactory.IdentifierName("Char")); - case SpecialType.System_SByte: - return SyntaxFactory.QualifiedName(SyntaxFactory.IdentifierName("System"), SyntaxFactory.IdentifierName("SByte")); - case SpecialType.System_Byte: - return SyntaxFactory.QualifiedName(SyntaxFactory.IdentifierName("System"), SyntaxFactory.IdentifierName("Byte")); - case SpecialType.System_Int16: - return SyntaxFactory.QualifiedName(SyntaxFactory.IdentifierName("System"), SyntaxFactory.IdentifierName("Int16")); - case SpecialType.System_UInt16: - return SyntaxFactory.QualifiedName(SyntaxFactory.IdentifierName("System"), SyntaxFactory.IdentifierName("UInt16")); - case SpecialType.System_Int32: - return SyntaxFactory.QualifiedName(SyntaxFactory.IdentifierName("System"), SyntaxFactory.IdentifierName("Int32")); - case SpecialType.System_UInt32: - return SyntaxFactory.QualifiedName(SyntaxFactory.IdentifierName("System"), SyntaxFactory.IdentifierName("UInt32")); - case SpecialType.System_Int64: - return SyntaxFactory.QualifiedName(SyntaxFactory.IdentifierName("System"), SyntaxFactory.IdentifierName("Int64")); - case SpecialType.System_UInt64: - return SyntaxFactory.QualifiedName(SyntaxFactory.IdentifierName("System"), SyntaxFactory.IdentifierName("UInt64")); - case SpecialType.System_Decimal: - return SyntaxFactory.QualifiedName(SyntaxFactory.IdentifierName("System"), SyntaxFactory.IdentifierName("Decimal")); - case SpecialType.System_Single: - return SyntaxFactory.QualifiedName(SyntaxFactory.IdentifierName("System"), SyntaxFactory.IdentifierName("Single")); - case SpecialType.System_Double: - return SyntaxFactory.QualifiedName(SyntaxFactory.IdentifierName("System"), SyntaxFactory.IdentifierName("Double")); - case SpecialType.System_String: - return SyntaxFactory.QualifiedName(SyntaxFactory.IdentifierName("System"), SyntaxFactory.IdentifierName("String")); - } - - if (symbol.IsTupleType) - { - return CreateTupleTypeSyntax(symbol); + var syntax = TryCreateSpecializedNamedTypeSyntax(symbol); + if (syntax != null) + { + return syntax; + } } if (symbol.Name == string.Empty || symbol.IsAnonymousType) { - return SyntaxFactory.QualifiedName(SyntaxFactory.IdentifierName("System"), SyntaxFactory.IdentifierName("Object")); - } - - if (symbol.IsNullable()) - { - // Can't have a nullable of a pointer type. i.e. "int*?" is illegal. - var innerType = symbol.TypeArguments.First(); - if (innerType.TypeKind != TypeKind.Pointer) - { - return AddInformationTo( - SyntaxFactory.NullableType(innerType.Accept(this)), symbol); - } + return CreateSystemObject(); } if (symbol.TypeParameters.Length == 0) { if (symbol.TypeKind == TypeKind.Error && symbol.Name == "var") { - return SyntaxFactory.QualifiedName(SyntaxFactory.IdentifierName("System"), SyntaxFactory.IdentifierName("Object")); + return CreateSystemObject(); } return symbol.Name.ToIdentifierName(); @@ -140,13 +112,53 @@ public TypeSyntax CreateSimpleTypeSyntax(INamedTypeSymbol symbol) var typeArguments = symbol.IsUnboundGenericType ? Enumerable.Repeat(SyntaxFactory.OmittedTypeArgument(), symbol.TypeArguments.Length) - : symbol.TypeArguments.Select(t => t.Accept(this)); + : symbol.TypeArguments.Select(t => t.GenerateTypeSyntax()); return SyntaxFactory.GenericName( symbol.Name.ToIdentifierToken(), SyntaxFactory.TypeArgumentList(SyntaxFactory.SeparatedList(typeArguments))); } + private static QualifiedNameSyntax CreateSystemObject() + { + return SyntaxFactory.QualifiedName( + SyntaxFactory.AliasQualifiedName( + CreateGlobalIdentifier(), + SyntaxFactory.IdentifierName("System")), + SyntaxFactory.IdentifierName("Object")); + } + + private static IdentifierNameSyntax CreateGlobalIdentifier() + { + return SyntaxFactory.IdentifierName(SyntaxFactory.Token(SyntaxKind.GlobalKeyword)); + } + + private TypeSyntax TryCreateSpecializedNamedTypeSyntax(INamedTypeSymbol symbol) + { + if (symbol.SpecialType == SpecialType.System_Void) + { + return SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.VoidKeyword)); + } + + if (symbol.IsTupleType) + { + return CreateTupleTypeSyntax(symbol); + } + + if (symbol.IsNullable()) + { + // Can't have a nullable of a pointer type. i.e. "int*?" is illegal. + var innerType = symbol.TypeArguments.First(); + if (innerType.TypeKind != TypeKind.Pointer) + { + return AddInformationTo( + SyntaxFactory.NullableType(innerType.GenerateTypeSyntax()), symbol); + } + } + + return null; + } + private TupleTypeSyntax CreateTupleTypeSyntax(INamedTypeSymbol symbol) { var list = new SeparatedSyntaxList(); @@ -157,10 +169,10 @@ private TupleTypeSyntax CreateTupleTypeSyntax(INamedTypeSymbol symbol) for (int i = 0; i < types.Length; i++) { var name = hasNames ? SyntaxFactory.IdentifierName(names[i]) : null; - list = list.Add(SyntaxFactory.TupleElement(GenerateTypeSyntax(types[i]), name)); + list = list.Add(SyntaxFactory.TupleElement(types[i].GenerateTypeSyntax(), name)); } - return SyntaxFactory.TupleType(list); + return AddInformationTo(SyntaxFactory.TupleType(list), symbol); } public override TypeSyntax VisitNamedType(INamedTypeSymbol symbol) @@ -199,10 +211,7 @@ public override TypeSyntax VisitNamedType(INamedTypeSymbol symbol) { if (symbol.TypeKind != TypeKind.Error) { - return AddInformationTo( - SyntaxFactory.AliasQualifiedName( - SyntaxFactory.IdentifierName(SyntaxFactory.Token(SyntaxKind.GlobalKeyword)), - simpleNameSyntax), symbol); + return AddGlobalAlias(symbol, simpleNameSyntax); } } else @@ -227,10 +236,7 @@ public override TypeSyntax VisitNamespace(INamespaceSymbol symbol) if (symbol.ContainingNamespace.IsGlobalNamespace) { - return AddInformationTo( - SyntaxFactory.AliasQualifiedName( - SyntaxFactory.IdentifierName(SyntaxFactory.Token(SyntaxKind.GlobalKeyword)), - syntax), symbol); + return AddGlobalAlias(symbol, syntax); } else { @@ -241,10 +247,20 @@ public override TypeSyntax VisitNamespace(INamespaceSymbol symbol) } } + private TypeSyntax AddGlobalAlias(INamespaceOrTypeSymbol symbol, SimpleNameSyntax syntax) + { + return AddInformationTo( + SyntaxFactory.AliasQualifiedName( + CreateGlobalIdentifier(), + syntax), symbol); + } + public override TypeSyntax VisitPointerType(IPointerTypeSymbol symbol) { + ThrowIfNameOnly(); + return AddInformationTo( - SyntaxFactory.PointerType(symbol.PointedAtType.Accept(this)), + SyntaxFactory.PointerType(symbol.PointedAtType.GenerateTypeSyntax()), symbol); } @@ -254,4 +270,4 @@ public override TypeSyntax VisitTypeParameter(ITypeParameterSymbol symbol) } } } -} +} \ No newline at end of file diff --git a/src/Workspaces/CSharp/Portable/Extensions/ITypeSymbolExtensions.cs b/src/Workspaces/CSharp/Portable/Extensions/ITypeSymbolExtensions.cs index a5919a540b9..a1cd9ee1d16 100644 --- a/src/Workspaces/CSharp/Portable/Extensions/ITypeSymbolExtensions.cs +++ b/src/Workspaces/CSharp/Portable/Extensions/ITypeSymbolExtensions.cs @@ -6,13 +6,11 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Symbols; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.ErrorReporting; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Simplification; -using Microsoft.CodeAnalysis.Text; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CSharp.Extensions @@ -25,10 +23,23 @@ internal static partial class ITypeSymbolExtensions return typeSymbol.Accept(ExpressionSyntaxGeneratorVisitor.Instance).WithAdditionalAnnotations(Simplifier.Annotation); } + public static NameSyntax GenerateNameSyntax( + this INamespaceOrTypeSymbol symbol) + { + return (NameSyntax)GenerateTypeSyntax(symbol, nameSyntax: true); + } + public static TypeSyntax GenerateTypeSyntax( - this ITypeSymbol typeSymbol) + this INamespaceOrTypeSymbol symbol) + { + return GenerateTypeSyntax(symbol, nameSyntax: false); + } + + private static TypeSyntax GenerateTypeSyntax( + INamespaceOrTypeSymbol symbol, bool nameSyntax) { - return typeSymbol.Accept(TypeSyntaxGeneratorVisitor.Instance).WithAdditionalAnnotations(Simplifier.Annotation); + return symbol.Accept(TypeSyntaxGeneratorVisitor.Create(nameSyntax)) + .WithAdditionalAnnotations(Simplifier.Annotation); } public static bool ContainingTypesOrSelfHasUnsafeKeyword(this ITypeSymbol containingType) diff --git a/src/Workspaces/CSharp/Portable/Extensions/SyntaxNodeExtensions.cs b/src/Workspaces/CSharp/Portable/Extensions/SyntaxNodeExtensions.cs index 92a4beab7de..75cbf14d455 100644 --- a/src/Workspaces/CSharp/Portable/Extensions/SyntaxNodeExtensions.cs +++ b/src/Workspaces/CSharp/Portable/Extensions/SyntaxNodeExtensions.cs @@ -98,6 +98,14 @@ public static IEnumerable GetEnclosingUsingDirectives(this .SelectMany(n => n.Usings)); } + public static IEnumerable GetEnclosingExternAliasDirectives(this SyntaxNode node) + { + return node.GetAncestorOrThis().Externs + .Concat(node.GetAncestorsOrThis() + .Reverse() + .SelectMany(n => n.Externs)); + } + public static bool IsUnsafeContext(this SyntaxNode node) { if (node.GetAncestor() != null) diff --git a/src/Workspaces/CSharp/Portable/Utilities/NameSyntaxComparer.cs b/src/Workspaces/CSharp/Portable/Utilities/NameSyntaxComparer.cs index bd69cd501da..00aa00f4366 100644 --- a/src/Workspaces/CSharp/Portable/Utilities/NameSyntaxComparer.cs +++ b/src/Workspaces/CSharp/Portable/Utilities/NameSyntaxComparer.cs @@ -1,10 +1,7 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.CSharp.Symbols; using Microsoft.CodeAnalysis.CSharp.Syntax; -using Microsoft.CodeAnalysis.Text; namespace Microsoft.CodeAnalysis.CSharp.Utilities { diff --git a/src/Workspaces/CSharpTest/CodeGeneration/SymbolEditorTests.cs b/src/Workspaces/CSharpTest/CodeGeneration/SymbolEditorTests.cs index b858980b2e5..3c23d3c6a54 100644 --- a/src/Workspaces/CSharpTest/CodeGeneration/SymbolEditorTests.cs +++ b/src/Workspaces/CSharpTest/CodeGeneration/SymbolEditorTests.cs @@ -14,7 +14,7 @@ using Roslyn.Test.Utilities; using Xunit; -namespace Microsoft.CodeAnalysis.CSharp.UnitTests.Editting +namespace Microsoft.CodeAnalysis.CSharp.UnitTests.Editing { public class SymbolEditorTests { diff --git a/src/Workspaces/CSharpTest/CodeGeneration/SyntaxGeneratorTests.cs b/src/Workspaces/CSharpTest/CodeGeneration/SyntaxGeneratorTests.cs index f0665479379..ed818a319e0 100644 --- a/src/Workspaces/CSharpTest/CodeGeneration/SyntaxGeneratorTests.cs +++ b/src/Workspaces/CSharpTest/CodeGeneration/SyntaxGeneratorTests.cs @@ -12,7 +12,7 @@ using Roslyn.Test.Utilities; using Xunit; -namespace Microsoft.CodeAnalysis.CSharp.UnitTests.Editting +namespace Microsoft.CodeAnalysis.CSharp.UnitTests.Editing { public class SyntaxGeneratorTests { @@ -257,7 +257,7 @@ public void TestSymbolTypeExpressions() VerifySyntax(_g.TypeExpression(genericType), "global::System.Collections.Generic.IEnumerable"); var arrayType = _emptyCompilation.CreateArrayTypeSymbol(_emptyCompilation.GetSpecialType(SpecialType.System_Int32)); - VerifySyntax(_g.TypeExpression(arrayType), "System.Int32[]"); + VerifySyntax(_g.TypeExpression(arrayType), "global::System.Int32[]"); } [Fact] @@ -343,7 +343,7 @@ public void TestObjectCreationExpressions() VerifySyntax( _g.ObjectCreationExpression(listOfIntType, _g.IdentifierName("y")), - "new global::System.Collections.Generic.List(y)"); // should this be 'int' or if not shouldn't it have global::? + "new global::System.Collections.Generic.List(y)"); // should this be 'int' or if not shouldn't it have global::? } [Fact] @@ -743,109 +743,109 @@ public void TestOperatorDeclaration() VerifySyntax( _g.OperatorDeclaration(OperatorKind.Addition, parameters, returnType), - "bool operator +(System.Int32 p0, System.String p1)\r\n{\r\n}"); + "bool operator +(global::System.Int32 p0, global::System.String p1)\r\n{\r\n}"); VerifySyntax( _g.OperatorDeclaration(OperatorKind.BitwiseAnd, parameters, returnType), - "bool operator &(System.Int32 p0, System.String p1)\r\n{\r\n}"); + "bool operator &(global::System.Int32 p0, global::System.String p1)\r\n{\r\n}"); VerifySyntax( _g.OperatorDeclaration(OperatorKind.BitwiseOr, parameters, returnType), - "bool operator |(System.Int32 p0, System.String p1)\r\n{\r\n}"); + "bool operator |(global::System.Int32 p0, global::System.String p1)\r\n{\r\n}"); VerifySyntax( _g.OperatorDeclaration(OperatorKind.Decrement, parameters, returnType), - "bool operator --(System.Int32 p0, System.String p1)\r\n{\r\n}"); + "bool operator --(global::System.Int32 p0, global::System.String p1)\r\n{\r\n}"); VerifySyntax( _g.OperatorDeclaration(OperatorKind.Division, parameters, returnType), - "bool operator /(System.Int32 p0, System.String p1)\r\n{\r\n}"); + "bool operator /(global::System.Int32 p0, global::System.String p1)\r\n{\r\n}"); VerifySyntax( _g.OperatorDeclaration(OperatorKind.Equality, parameters, returnType), - "bool operator ==(System.Int32 p0, System.String p1)\r\n{\r\n}"); + "bool operator ==(global::System.Int32 p0, global::System.String p1)\r\n{\r\n}"); VerifySyntax( _g.OperatorDeclaration(OperatorKind.ExclusiveOr, parameters, returnType), - "bool operator ^(System.Int32 p0, System.String p1)\r\n{\r\n}"); + "bool operator ^(global::System.Int32 p0, global::System.String p1)\r\n{\r\n}"); VerifySyntax( _g.OperatorDeclaration(OperatorKind.False, parameters, returnType), - "bool operator false (System.Int32 p0, System.String p1)\r\n{\r\n}"); + "bool operator false (global::System.Int32 p0, global::System.String p1)\r\n{\r\n}"); VerifySyntax( _g.OperatorDeclaration(OperatorKind.GreaterThan, parameters, returnType), - "bool operator>(System.Int32 p0, System.String p1)\r\n{\r\n}"); + "bool operator>(global::System.Int32 p0, global::System.String p1)\r\n{\r\n}"); VerifySyntax( _g.OperatorDeclaration(OperatorKind.GreaterThanOrEqual, parameters, returnType), - "bool operator >=(System.Int32 p0, System.String p1)\r\n{\r\n}"); + "bool operator >=(global::System.Int32 p0, global::System.String p1)\r\n{\r\n}"); VerifySyntax( _g.OperatorDeclaration(OperatorKind.Increment, parameters, returnType), - "bool operator ++(System.Int32 p0, System.String p1)\r\n{\r\n}"); + "bool operator ++(global::System.Int32 p0, global::System.String p1)\r\n{\r\n}"); VerifySyntax( _g.OperatorDeclaration(OperatorKind.Inequality, parameters, returnType), - "bool operator !=(System.Int32 p0, System.String p1)\r\n{\r\n}"); + "bool operator !=(global::System.Int32 p0, global::System.String p1)\r\n{\r\n}"); VerifySyntax( _g.OperatorDeclaration(OperatorKind.LeftShift, parameters, returnType), - "bool operator <<(System.Int32 p0, System.String p1)\r\n{\r\n}"); + "bool operator <<(global::System.Int32 p0, global::System.String p1)\r\n{\r\n}"); VerifySyntax( _g.OperatorDeclaration(OperatorKind.LessThan, parameters, returnType), - "bool operator <(System.Int32 p0, System.String p1)\r\n{\r\n}"); + "bool operator <(global::System.Int32 p0, global::System.String p1)\r\n{\r\n}"); VerifySyntax( _g.OperatorDeclaration(OperatorKind.LessThanOrEqual, parameters, returnType), - "bool operator <=(System.Int32 p0, System.String p1)\r\n{\r\n}"); + "bool operator <=(global::System.Int32 p0, global::System.String p1)\r\n{\r\n}"); VerifySyntax( _g.OperatorDeclaration(OperatorKind.LogicalNot, parameters, returnType), - "bool operator !(System.Int32 p0, System.String p1)\r\n{\r\n}"); + "bool operator !(global::System.Int32 p0, global::System.String p1)\r\n{\r\n}"); VerifySyntax( _g.OperatorDeclaration(OperatorKind.Modulus, parameters, returnType), - "bool operator %(System.Int32 p0, System.String p1)\r\n{\r\n}"); + "bool operator %(global::System.Int32 p0, global::System.String p1)\r\n{\r\n}"); VerifySyntax( _g.OperatorDeclaration(OperatorKind.Multiply, parameters, returnType), - "bool operator *(System.Int32 p0, System.String p1)\r\n{\r\n}"); + "bool operator *(global::System.Int32 p0, global::System.String p1)\r\n{\r\n}"); VerifySyntax( _g.OperatorDeclaration(OperatorKind.OnesComplement, parameters, returnType), - "bool operator ~(System.Int32 p0, System.String p1)\r\n{\r\n}"); + "bool operator ~(global::System.Int32 p0, global::System.String p1)\r\n{\r\n}"); VerifySyntax( _g.OperatorDeclaration(OperatorKind.RightShift, parameters, returnType), - "bool operator >>(System.Int32 p0, System.String p1)\r\n{\r\n}"); + "bool operator >>(global::System.Int32 p0, global::System.String p1)\r\n{\r\n}"); VerifySyntax( _g.OperatorDeclaration(OperatorKind.Subtraction, parameters, returnType), - "bool operator -(System.Int32 p0, System.String p1)\r\n{\r\n}"); + "bool operator -(global::System.Int32 p0, global::System.String p1)\r\n{\r\n}"); VerifySyntax( _g.OperatorDeclaration(OperatorKind.True, parameters, returnType), - "bool operator true (System.Int32 p0, System.String p1)\r\n{\r\n}"); + "bool operator true (global::System.Int32 p0, global::System.String p1)\r\n{\r\n}"); VerifySyntax( _g.OperatorDeclaration(OperatorKind.UnaryNegation, parameters, returnType), - "bool operator -(System.Int32 p0, System.String p1)\r\n{\r\n}"); + "bool operator -(global::System.Int32 p0, global::System.String p1)\r\n{\r\n}"); VerifySyntax( _g.OperatorDeclaration(OperatorKind.UnaryPlus, parameters, returnType), - "bool operator +(System.Int32 p0, System.String p1)\r\n{\r\n}"); + "bool operator +(global::System.Int32 p0, global::System.String p1)\r\n{\r\n}"); // Conversion operators VerifySyntax( _g.OperatorDeclaration(OperatorKind.ImplicitConversion, parameters, returnType), - "implicit operator bool (System.Int32 p0, System.String p1)\r\n{\r\n}"); + "implicit operator bool (global::System.Int32 p0, global::System.String p1)\r\n{\r\n}"); VerifySyntax( _g.OperatorDeclaration(OperatorKind.ExplicitConversion, parameters, returnType), - "explicit operator bool (System.Int32 p0, System.String p1)\r\n{\r\n}"); + "explicit operator bool (global::System.Int32 p0, global::System.String p1)\r\n{\r\n}"); } [Fact] diff --git a/src/Workspaces/CoreTest/Editting/SyntaxEditorTests.cs b/src/Workspaces/CoreTest/Editting/SyntaxEditorTests.cs index 2c5d831b3ec..35e9734ff6e 100644 --- a/src/Workspaces/CoreTest/Editting/SyntaxEditorTests.cs +++ b/src/Workspaces/CoreTest/Editting/SyntaxEditorTests.cs @@ -12,7 +12,7 @@ using Roslyn.Test.Utilities; using Xunit; -namespace Microsoft.CodeAnalysis.CSharp.UnitTests.Editting +namespace Microsoft.CodeAnalysis.CSharp.UnitTests.Editing { public class SyntaxEditorTests { -- GitLab