提交 2ede8fdd 编写于 作者: R Ravi Chande 提交者: GitHub

Merge pull request #10512 from rchande/overrideusingsystem

When inserting overridden members from completion, do not add a using…
......@@ -1171,7 +1171,9 @@ protected internal override void foo()
[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task CommitAbstractMethodThrows()
{
var markupBeforeCommit = @"abstract class c
var markupBeforeCommit = @"using System;
abstract class c
{
public abstract void foo();
}
......@@ -1599,9 +1601,7 @@ class d : MyIndexer<T>
override $$
}";
var expectedCodeAfterCommit = @"using System;
public class MyIndexer<T>
var expectedCodeAfterCommit = @"public class MyIndexer<T>
{
private T[] arr = new T[100];
public abstract T this[int i] { get; set; }
......@@ -1613,12 +1613,12 @@ class d : MyIndexer<T>
{
get
{
throw new NotImplementedException();$$
throw new System.NotImplementedException();$$
}
set
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}
}";
......@@ -1729,7 +1729,9 @@ public override ArgumentException foo(Exception e)
[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task CommitEscapedMethodName()
{
var markupBeforeCommit = @"public abstract class Base
var markupBeforeCommit = @"using System;
public abstract class Base
{
public abstract void @class();
}
......@@ -1829,7 +1831,9 @@ public override void foo(int @class)
[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task CommitRefParameter()
{
var markupBeforeCommit = @"public abstract class Base
var markupBeforeCommit = @"using System;
public abstract class Base
{
public abstract void foo(int x, ref string y);
}
......@@ -1860,7 +1864,9 @@ public override void foo(int x, ref string y)
[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task CommitOutParameter()
{
var markupBeforeCommit = @"public abstract class Base
var markupBeforeCommit = @"using System;
public abstract class Base
{
public abstract void foo(int x, out string y);
}
......@@ -2555,5 +2561,72 @@ static void Main(string[] args)
Assert.Equal(change.Span, TextSpan.FromBounds(136, 145));
}
}
[WorkItem(8257, "https://github.com/dotnet/roslyn/issues/8257")]
[WpfFact, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task NotImplementedQualifiedWhenSystemUsingNotPresent_Property()
{
var markupBeforeCommit = @"abstract class C
{
public abstract int foo { get; set; };
}
class Program : C
{
override $$
}";
var expectedCodeAfterCommit = @"abstract class C
{
public abstract int foo { get; set; };
}
class Program : C
{
public override int foo
{
get
{
throw new System.NotImplementedException();$$
}
set
{
throw new System.NotImplementedException();
}
}
}";
await VerifyCustomCommitProviderAsync(markupBeforeCommit, "foo", expectedCodeAfterCommit);
}
[WorkItem(8257, "https://github.com/dotnet/roslyn/issues/8257")]
public async Task NotImplementedQualifiedWhenSystemUsingNotPresent_Method()
{
var markupBeforeCommit = @"abstract class C
{
public abstract void foo();
}
class Program : C
{
override $$
}";
var expectedCodeAfterCommit = @"abstract class C
{
public abstract void foo();
}
class Program : C
{
public override void foo()
{
throw new System.NotImplementedException();$$
}
}";
await VerifyCustomCommitProviderAsync(markupBeforeCommit, "foo()", expectedCodeAfterCommit);
}
}
}
\ No newline at end of file
......@@ -244,15 +244,13 @@ public async Task CommitInPartialClass()
partial $$
}";
var expectedCodeAfterCommit = @"using System;
partial class c
var expectedCodeAfterCommit = @"partial class c
{
partial void foo();
partial void foo()
{
throw new NotImplementedException();$$
throw new System.NotImplementedException();$$
}
}";
......@@ -269,15 +267,13 @@ public async Task CommitGenericPartialMethod()
partial $$
}";
var expectedCodeAfterCommit = @"using System;
partial class c<T>
var expectedCodeAfterCommit = @"partial class c<T>
{
partial void foo(T bar);
partial void foo(T bar)
{
throw new NotImplementedException();$$
throw new System.NotImplementedException();$$
}
}";
......@@ -294,15 +290,13 @@ public async Task CommitMethodErasesPrivate()
private partial $$
}";
var expectedCodeAfterCommit = @"using System;
partial class c
var expectedCodeAfterCommit = @"partial class c
{
partial void foo();
partial void foo()
{
throw new NotImplementedException();$$
throw new System.NotImplementedException();$$
}
}";
......@@ -322,9 +316,7 @@ partial class c
partial $$
}";
var expectedCodeAfterCommit = @"using System;
partial class c
var expectedCodeAfterCommit = @"partial class c
{
partial void foo();
}
......@@ -333,7 +325,7 @@ partial class c
{
partial void foo()
{
throw new NotImplementedException();$$
throw new System.NotImplementedException();$$
}
}";
......@@ -350,15 +342,13 @@ public async Task CommitInPartialStruct()
partial $$
}";
var expectedCodeAfterCommit = @"using System;
partial struct c
var expectedCodeAfterCommit = @"partial struct c
{
partial void foo();
partial void foo()
{
throw new NotImplementedException();$$
throw new System.NotImplementedException();$$
}
}";
......@@ -469,9 +459,7 @@ partial class PClass
}
";
var expected = @"using System;
namespace PartialClass
var expected = @"namespace PartialClass
{
partial class PClass
{
......@@ -479,7 +467,7 @@ partial class PClass
partial void PMethod(int i)
{
throw new NotImplementedException();$$
throw new System.NotImplementedException();$$
}
}
}
......
......@@ -70,9 +70,7 @@ static void Main(string[] args)
{
}
}",
@"using System;
abstract class Foo
@"abstract class Foo
{
protected abstract string FooMethod();
public abstract void Blah();
......@@ -95,12 +93,12 @@ static void Main(string[] args)
public override void Blah()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
protected override string FooMethod()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}");
}
......@@ -118,9 +116,7 @@ public async Task TestMethodWithTupleNames()
class [|Program|] : Base
{
}",
@"using System;
abstract class Base
@"abstract class Base
{
protected abstract (int a, int b) Method((string, string d) x);
}
......@@ -129,7 +125,7 @@ class Program : Base
{
protected override (int a, int b) Method((string, string d) x)
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}");
}
......@@ -161,9 +157,7 @@ public async Task TestOptionalIntParameter()
class [|b|] : d
{
}",
@"using System;
abstract class d
@"abstract class d
{
public abstract void foo(int x = 3);
}
......@@ -172,7 +166,7 @@ class b : d
{
public override void foo(int x = 3)
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}");
}
......@@ -189,9 +183,7 @@ public async Task TestOptionalCharParameter()
class [|b|] : d
{
}",
@"using System;
abstract class d
@"abstract class d
{
public abstract void foo(char x = 'a');
}
......@@ -200,7 +192,7 @@ class b : d
{
public override void foo(char x = 'a')
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}");
}
......@@ -217,9 +209,7 @@ public async Task TestOptionalStringParameter()
class [|b|] : d
{
}",
@"using System;
abstract class d
@"abstract class d
{
public abstract void foo(string x = ""x"");
}
......@@ -228,7 +218,7 @@ class b : d
{
public override void foo(string x = ""x"")
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}");
}
......@@ -245,9 +235,7 @@ public async Task TestOptionalShortParameter()
class [|b|] : d
{
}",
@"using System;
abstract class d
@"abstract class d
{
public abstract void foo(short x = 3);
}
......@@ -256,7 +244,7 @@ class b : d
{
public override void foo(short x = 3)
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}");
}
......@@ -273,9 +261,7 @@ public async Task TestOptionalDecimalParameter()
class [|b|] : d
{
}",
@"using System;
abstract class d
@"abstract class d
{
public abstract void foo(decimal x = 3);
}
......@@ -284,7 +270,7 @@ class b : d
{
public override void foo(decimal x = 3)
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}");
}
......@@ -301,9 +287,7 @@ public async Task TestOptionalDoubleParameter()
class [|b|] : d
{
}",
@"using System;
abstract class d
@"abstract class d
{
public abstract void foo(double x = 3);
}
......@@ -312,7 +296,7 @@ class b : d
{
public override void foo(double x = 3)
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}");
}
......@@ -329,9 +313,7 @@ public async Task TestOptionalLongParameter()
class [|b|] : d
{
}",
@"using System;
abstract class d
@"abstract class d
{
public abstract void foo(long x = 3);
}
......@@ -340,7 +322,7 @@ class b : d
{
public override void foo(long x = 3)
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}");
}
......@@ -357,9 +339,7 @@ public async Task TestOptionalFloatParameter()
class [|b|] : d
{
}",
@"using System;
abstract class d
@"abstract class d
{
public abstract void foo(float x = 3);
}
......@@ -368,7 +348,7 @@ class b : d
{
public override void foo(float x = 3)
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}");
}
......@@ -385,9 +365,7 @@ public async Task TestOptionalUshortParameter()
class [|b|] : d
{
}",
@"using System;
abstract class d
@"abstract class d
{
public abstract void foo(ushort x = 3);
}
......@@ -396,7 +374,7 @@ class b : d
{
public override void foo(ushort x = 3)
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}");
}
......@@ -413,9 +391,7 @@ public async Task TestOptionalUintParameter()
class [|b|] : d
{
}",
@"using System;
abstract class d
@"abstract class d
{
public abstract void foo(uint x = 3);
}
......@@ -424,7 +400,7 @@ class b : d
{
public override void foo(uint x = 3)
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}");
}
......@@ -441,9 +417,7 @@ public async Task TestOptionalUlongParameter()
class [|b|] : d
{
}",
@"using System;
abstract class d
@"abstract class d
{
public abstract void foo(ulong x = 3);
}
......@@ -452,7 +426,7 @@ class b : d
{
public override void foo(ulong x = 3)
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}");
}
......@@ -473,9 +447,7 @@ abstract class d
class [|c|] : d
{
}",
@"using System;
struct b
@"struct b
{
}
......@@ -488,7 +460,7 @@ class c : d
{
public override void foo(b x = default(b))
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}");
}
......@@ -510,9 +482,7 @@ abstract class d
class [|c|] : d
{
}",
@"using System;
struct b
@"struct b
{
}
......@@ -525,7 +495,7 @@ class c : d
{
public override void m(b? x = default(b?), b? y = default(b?))
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}");
}
......@@ -543,9 +513,7 @@ public async Task TestOptionalNullableIntParameter()
class [|c|] : d
{
}",
@"using System;
abstract class d
@"abstract class d
{
public abstract void m(int? x = 5, int? y = default(int?));
}
......@@ -554,7 +522,7 @@ class c : d
{
public override void m(int? x = 5, int? y = default(int?))
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}");
}
......@@ -575,9 +543,7 @@ abstract class d
class [|c|] : d
{
}",
@"using System;
class b
@"class b
{
}
......@@ -590,7 +556,7 @@ class c : d
{
public override void foo(b x = null)
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}");
}
......@@ -608,9 +574,7 @@ public async Task TestDifferentAccessorAccessibility()
class [|c2|] : c1
{
}",
@"using System;
abstract class c1
@"abstract class c1
{
public abstract c1 this[c1 x] { get; internal set; }
}
......@@ -621,12 +585,12 @@ class c2 : c1
{
get
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
internal set
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}
}");
......@@ -885,9 +849,7 @@ abstract class B : A
class [|C|] : B
{
}",
@"using System;
class A
@"class A
{
public virtual void Foo(int x, params int[] y)
{
......@@ -903,7 +865,7 @@ class C : B
{
public override void Foo(int x, params int[] y)
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}");
}
......@@ -921,9 +883,7 @@ public async Task TestNullPointerType()
class [|D|] : C
{
}",
@"using System;
abstract class C
@"abstract class C
{
unsafe public abstract void Foo(int* x = null);
}
......@@ -932,7 +892,7 @@ class D : C
{
public override unsafe void Foo(int* x = null)
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}");
}
......@@ -954,8 +914,6 @@ class [|D|] : C
}",
@"extern alias var;
using System;
abstract class C
{
public abstract void Foo(var::X x);
......@@ -965,7 +923,7 @@ class D : C
{
public override void Foo(X x)
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}");
}
......@@ -986,9 +944,7 @@ class [|T|] : A<T>
}
}
}",
@"using System;
abstract class A<T>
@"abstract class A<T>
{
public abstract void M(T x);
......@@ -998,7 +954,7 @@ class T : A<T>
{
public override void M(B.T x)
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}
}
......@@ -1019,9 +975,7 @@ class [|T|] : A<B.T> { }
}
}
",
@"using System;
abstract class A<T>
@"abstract class A<T>
{
public abstract void M(T x);
abstract class B : A<B>
......@@ -1030,7 +984,7 @@ class T : A<B.T>
{
public override void M(A<A<T>.B>.B.T x)
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}
}
......@@ -1215,16 +1169,14 @@ public async Task TestCodeStyle_Method1()
class [|T|] : A
{
}",
@"using System;
abstract class A
@"abstract class A
{
public abstract void M(int x);
}
class T : A
{
public override void M(int x) => throw new NotImplementedException();
public override void M(int x) => throw new System.NotImplementedException();
}", options: Option(CSharpCodeStyleOptions.PreferExpressionBodiedMethods, CodeStyleOptions.TrueWithNoneEnforcement));
}
......@@ -1241,16 +1193,14 @@ public async Task TestCodeStyle_Property1()
class [|T|] : A
{
}",
@"using System;
abstract class A
@"abstract class A
{
public abstract int M { get; }
}
class T : A
{
public override int M => throw new NotImplementedException();
public override int M => throw new System.NotImplementedException();
}", options: Option(CSharpCodeStyleOptions.PreferExpressionBodiedProperties, CodeStyleOptions.TrueWithNoneEnforcement));
}
......@@ -1267,9 +1217,7 @@ public async Task TestCodeStyle_Property3()
class [|T|] : A
{
}",
@"using System;
abstract class A
@"abstract class A
{
public abstract int M { set; }
}
......@@ -1280,7 +1228,7 @@ public override int M
{
set
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}
}", options: OptionsSet(
......@@ -1301,9 +1249,7 @@ public async Task TestCodeStyle_Property4()
class [|T|] : A
{
}",
@"using System;
abstract class A
@"abstract class A
{
public abstract int M { get; set; }
}
......@@ -1314,12 +1260,12 @@ public override int M
{
get
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
set
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}
}", options: OptionsSet(
......@@ -1340,16 +1286,14 @@ public async Task TestCodeStyle_Indexers1()
class [|T|] : A
{
}",
@"using System;
abstract class A
@"abstract class A
{
public abstract int this[int i] { get; }
}
class T : A
{
public override int this[int i] => throw new NotImplementedException();
public override int this[int i] => throw new System.NotImplementedException();
}", options: Option(CSharpCodeStyleOptions.PreferExpressionBodiedIndexers, CodeStyleOptions.TrueWithNoneEnforcement));
}
......@@ -1366,9 +1310,7 @@ public async Task TestCodeStyle_Indexer3()
class [|T|] : A
{
}",
@"using System;
abstract class A
@"abstract class A
{
public abstract int this[int i] { set; }
}
......@@ -1379,7 +1321,7 @@ class T : A
{
set
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}
}", options: OptionsSet(
......@@ -1400,9 +1342,7 @@ public async Task TestCodeStyle_Indexer4()
class [|T|] : A
{
}",
@"using System;
abstract class A
@"abstract class A
{
public abstract int this[int i] { get; set; }
}
......@@ -1413,12 +1353,12 @@ class T : A
{
get
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
set
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}
}", options: OptionsSet(
......@@ -1439,9 +1379,7 @@ public async Task TestCodeStyle_Accessor1()
class [|T|] : A
{
}",
@"using System;
abstract class A
@"abstract class A
{
public abstract int M { get; }
}
......@@ -1450,7 +1388,7 @@ class T : A
{
public override int M
{
get => throw new NotImplementedException();
get => throw new System.NotImplementedException();
}
}", options: OptionsSet(
SingleOption(CSharpCodeStyleOptions.PreferExpressionBodiedProperties, false, NotificationOption.None),
......@@ -1470,9 +1408,7 @@ public async Task TestCodeStyle_Accessor3()
class [|T|] : A
{
}",
@"using System;
abstract class A
@"abstract class A
{
public abstract int M { set; }
}
......@@ -1481,7 +1417,7 @@ class T : A
{
public override int M
{
set => throw new NotImplementedException();
set => throw new System.NotImplementedException();
}
}", options: Option(CSharpCodeStyleOptions.PreferExpressionBodiedAccessors, CodeStyleOptions.TrueWithNoneEnforcement));
}
......@@ -1499,9 +1435,7 @@ public async Task TestCodeStyle_Accessor4()
class [|T|] : A
{
}",
@"using System;
abstract class A
@"abstract class A
{
public abstract int M { get; set; }
}
......@@ -1510,8 +1444,8 @@ class T : A
{
public override int M
{
get => throw new NotImplementedException();
set => throw new NotImplementedException();
get => throw new System.NotImplementedException();
set => throw new System.NotImplementedException();
}
}", options: Option(CSharpCodeStyleOptions.PreferExpressionBodiedAccessors, CodeStyleOptions.TrueWithNoneEnforcement));
}
......@@ -1530,9 +1464,7 @@ class [|Derived|] : Base
{
void Foo() { }
}",
@"using System;
abstract class Base
@"abstract class Base
{
public abstract int Prop { get; }
}
......@@ -1541,7 +1473,7 @@ class Derived : Base
{
void Foo() { }
public override int Prop => throw new NotImplementedException();
public override int Prop => throw new System.NotImplementedException();
}", options: Option(ImplementTypeOptions.InsertionBehavior, ImplementTypeInsertionBehavior.AtTheEnd));
}
......@@ -1567,7 +1499,6 @@ public class [|Foo2|] : Foo // Implement Abstract Class
}",
@"// Copyright ...
using System;
using System.Collections.Generic;
using Microsoft.Win32;
......@@ -1582,7 +1513,7 @@ public class Foo2 : Foo // Implement Abstract Class
{
public override void Bar(List<object> values)
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}
}", compareTokens: false);
......
......@@ -64,8 +64,6 @@ class C3 : A1, I1
<Workspace>
<Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document>
using System;
public abstract class A1
{
public abstract void F1();
......@@ -80,14 +78,14 @@ class B1 : A1
{
public override void F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
class C1 : A1, I1
{
public override void F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}
}
......@@ -169,8 +167,6 @@ class C3 : A1, I1
<Workspace>
<Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document>
using System;
public abstract class A1
{
public abstract void F1();
......@@ -185,33 +181,31 @@ class B1 : A1
{
public override void F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
class C1 : A1, I1
{
public override void F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}
}
</Document>
<Document>
using System;
class B2 : A1
{
public override void F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
class C2 : A1, I1
{
public override void F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}
}
......@@ -286,8 +280,6 @@ class C3 : A1, I1
<Workspace>
<Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document>
using System;
public abstract class A1
{
public abstract void F1();
......@@ -302,33 +294,31 @@ class B1 : A1
{
public override void F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
class C1 : A1, I1
{
public override void F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}
}
</Document>
<Document>
using System;
class B2 : A1
{
public override void F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
class C2 : A1, I1
{
public override void F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}
}
......@@ -337,20 +327,18 @@ public override void F1()
<Project Language=""C#"" AssemblyName=""Assembly2"" CommonReferences=""true"">
<ProjectReference>Assembly1</ProjectReference>
<Document>
using System;
class B3 : A1
{
public override void F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
class C3 : A1, I1
{
public override void F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}
}
......@@ -419,8 +407,6 @@ class C3 : A1, I1
<Workspace>
<Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document>
using System;
public abstract class A1
{
public abstract void F1();
......@@ -435,33 +421,31 @@ class B1 : A1
{
public override void F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
class C1 : A1, I1
{
public override void F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}
}
</Document>
<Document>
using System;
class B2 : A1
{
public override void F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
class C2 : A1, I1
{
public override void F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}
}
......
......@@ -65,8 +65,6 @@ class C3 : I1, I2
<Workspace>
<Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document>
using System;
public interface I1
{
void F1();
......@@ -81,14 +79,14 @@ class B1 : I1, I2
{
public void F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
class C1 : I1, I2
{
public void F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}
}
......@@ -172,8 +170,6 @@ class C3 : I1, I2
<Workspace>
<Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document>
using System;
public interface I1
{
void F1();
......@@ -188,33 +184,31 @@ class B1 : I1, I2
{
public void F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
class C1 : I1, I2
{
public void F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}
}
</Document>
<Document>
using System;
class B2 : I1, I2
{
public void F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
class C2 : I1, I2
{
public void F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}
}
......@@ -290,8 +284,6 @@ class C3 : I1, I2
<Workspace>
<Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document>
using System;
public interface I1
{
void F1();
......@@ -306,33 +298,31 @@ class B1 : I1, I2
{
void I2.F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
class C1 : I1, I2
{
void I2.F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}
}
</Document>
<Document>
using System;
class B2 : I1, I2
{
void I2.F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
class C2 : I1, I2
{
void I2.F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}
}
......@@ -341,20 +331,18 @@ void I2.F1()
<Project Language=""C#"" AssemblyName=""Assembly2"" CommonReferences=""true"">
<ProjectReference>Assembly1</ProjectReference>
<Document>
using System;
class B3 : I1, I2
{
void I2.F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
class C3 : I1, I2
{
void I2.F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}
}
......@@ -428,8 +416,6 @@ class C3 : I1, I2
<Workspace>
<Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document>
using System;
public interface I1
{
void F1();
......@@ -444,33 +430,31 @@ class B1 : I1, I2
{
void I2.F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
class C1 : I1, I2
{
void I2.F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}
}
</Document>
<Document>
using System;
class B2 : I1, I2
{
void I2.F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
class C2 : I1, I2
{
void I2.F1()
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}
}
}
......
......@@ -844,7 +844,9 @@ End Class</a>
<WpfFact, Trait(Traits.Feature, Traits.Features.Completion)>
Public Async Function TestCommitAbstractThrows() As Task
Dim markupBeforeCommit = <a>Public MustInherit Class c
Dim markupBeforeCommit = <a>Imports System
Public MustInherit Class c
Public MustOverride Sub foo()
End Class
......@@ -1407,9 +1409,7 @@ Class Derived
Overrides $$
End Class</a>
Dim expectedCode = <a>Imports System
MustInherit Class CBase
Dim expectedCode = <a>MustInherit Class CBase
MustOverride Sub Foo()
End Class
......@@ -1417,7 +1417,7 @@ Class Derived
Inherits CBase
Public Overrides Sub Foo()
Throw New NotImplementedException()$$
Throw New System.NotImplementedException()$$
End Sub
End Class</a>
......
......@@ -23,18 +23,17 @@ End Class
Public Class [|Bar|]
Inherits Foo
End Class",
"Imports System
Public MustInherit Class Foo
"Public MustInherit Class Foo
Public MustOverride Sub Foo(i As Integer)
Protected MustOverride Function Bar(s As String, ByRef d As Double) As Boolean
End Class
Public Class Bar
Inherits Foo
Public Overrides Sub Foo(i As Integer)
Throw New NotImplementedException()
Throw New System.NotImplementedException()
End Sub
Protected Overrides Function Bar(s As String, ByRef d As Double) As Boolean
Throw New NotImplementedException()
Throw New System.NotImplementedException()
End Function
End Class")
End Function
......@@ -48,14 +47,13 @@ End Class
Public Class [|Derived|]
Inherits Base
End Class",
"Imports System
Public MustInherit Class Base
"Public MustInherit Class Base
Protected MustOverride Function Bar(x As (a As Integer, Integer)) As (c As Integer, Integer)
End Class
Public Class Derived
Inherits Base
Protected Overrides Function Bar(x As (a As Integer, Integer)) As (c As Integer, Integer)
Throw New NotImplementedException()
Throw New System.NotImplementedException()
End Function
End Class")
End Function
......@@ -69,14 +67,13 @@ End Class
Class [|c|]
Inherits b
End Class",
"Imports System
MustInherit Class b
"MustInherit Class b
Public MustOverride Sub g(Optional x As Integer = 3)
End Class
Class c
Inherits b
Public Overrides Sub g(Optional x As Integer = 3)
Throw New NotImplementedException()
Throw New System.NotImplementedException()
End Sub
End Class")
End Function
......@@ -90,14 +87,13 @@ End Class
Class [|c|]
Inherits b
End Class",
"Imports System
MustInherit Class b
"MustInherit Class b
Public MustOverride Sub g(Optional x As Boolean = True)
End Class
Class c
Inherits b
Public Overrides Sub g(Optional x As Boolean = True)
Throw New NotImplementedException()
Throw New System.NotImplementedException()
End Sub
End Class")
End Function
......@@ -111,14 +107,13 @@ End Class
Class [|c|]
Inherits b
End Class",
"Imports System
MustInherit Class b
"MustInherit Class b
Public MustOverride Sub g(Optional x As Boolean = False)
End Class
Class c
Inherits b
Public Overrides Sub g(Optional x As Boolean = False)
Throw New NotImplementedException()
Throw New System.NotImplementedException()
End Sub
End Class")
End Function
......@@ -132,14 +127,13 @@ End Class
Class [|c|]
Inherits b
End Class",
"Imports System
MustInherit Class b
"MustInherit Class b
Public MustOverride Sub g(Optional x As String = ""a"")
End Class
Class c
Inherits b
Public Overrides Sub g(Optional x As String = ""a"")
Throw New NotImplementedException()
Throw New System.NotImplementedException()
End Sub
End Class")
End Function
......@@ -153,14 +147,13 @@ End Class
Class [|c|]
Inherits b
End Class",
"Imports System
MustInherit Class b
"MustInherit Class b
Public MustOverride Sub g(Optional x As Char = ""c""c)
End Class
Class c
Inherits b
Public Overrides Sub g(Optional x As Char = ""c""c)
Throw New NotImplementedException()
Throw New System.NotImplementedException()
End Sub
End Class")
End Function
......@@ -174,14 +167,13 @@ End Class
Class [|c|]
Inherits b
End Class",
"Imports System
MustInherit Class b
"MustInherit Class b
Public MustOverride Sub g(Optional x As Long = 3)
End Class
Class c
Inherits b
Public Overrides Sub g(Optional x As Long = 3)
Throw New NotImplementedException()
Throw New System.NotImplementedException()
End Sub
End Class")
End Function
......@@ -195,14 +187,14 @@ End Class
Class [|c|]
Inherits b
End Class",
"Imports System
"
MustInherit Class b
Public MustOverride Sub g(Optional x As Short = 3)
End Class
Class c
Inherits b
Public Overrides Sub g(Optional x As Short = 3)
Throw New NotImplementedException()
Throw New System.NotImplementedException()
End Sub
End Class")
End Function
......@@ -216,14 +208,14 @@ End Class
Class [|c|]
Inherits b
End Class",
"Imports System
"
MustInherit Class b
Public MustOverride Sub g(Optional x As UShort = 3)
End Class
Class c
Inherits b
Public Overrides Sub g(Optional x As UShort = 3)
Throw New NotImplementedException()
Throw New System.NotImplementedException()
End Sub
End Class")
End Function
......@@ -237,14 +229,13 @@ End Class
Class [|c|]
Inherits b
End Class",
"Imports System
MustInherit Class b
"MustInherit Class b
Public MustOverride Sub g(Optional x As Integer = -3)
End Class
Class c
Inherits b
Public Overrides Sub g(Optional x As Integer = -3)
Throw New NotImplementedException()
Throw New System.NotImplementedException()
End Sub
End Class")
End Function
......@@ -258,14 +249,13 @@ End Class
Class [|c|]
Inherits b
End Class",
"Imports System
MustInherit Class b
"MustInherit Class b
Public MustOverride Sub g(Optional x As UInteger = 3)
End Class
Class c
Inherits b
Public Overrides Sub g(Optional x As UInteger = 3)
Throw New NotImplementedException()
Throw New System.NotImplementedException()
End Sub
End Class")
End Function
......@@ -279,14 +269,13 @@ End Class
Class [|c|]
Inherits b
End Class",
"Imports System
MustInherit Class b
"MustInherit Class b
Public MustOverride Sub g(Optional x As ULong = 3)
End Class
Class c
Inherits b
Public Overrides Sub g(Optional x As ULong = 3)
Throw New NotImplementedException()
Throw New System.NotImplementedException()
End Sub
End Class")
End Function
......@@ -300,14 +289,13 @@ End Class
Class [|c|]
Inherits b
End Class",
"Imports System
MustInherit Class b
"MustInherit Class b
Public MustOverride Sub g(Optional x As Decimal = 3)
End Class
Class c
Inherits b
Public Overrides Sub g(Optional x As Decimal = 3)
Throw New NotImplementedException()
Throw New System.NotImplementedException()
End Sub
End Class")
End Function
......@@ -321,14 +309,13 @@ End Class
Class [|c|]
Inherits b
End Class",
"Imports System
MustInherit Class b
"MustInherit Class b
Public MustOverride Sub g(Optional x As Double = 3)
End Class
Class c
Inherits b
Public Overrides Sub g(Optional x As Double = 3)
Throw New NotImplementedException()
Throw New System.NotImplementedException()
End Sub
End Class")
End Function
......@@ -344,8 +331,7 @@ End Class
Class [|c|]
Inherits b
End Class",
"Imports System
Structure S
"Structure S
End Structure
MustInherit Class b
Public MustOverride Sub g(Optional x As S = Nothing)
......@@ -353,7 +339,7 @@ End Class
Class c
Inherits b
Public Overrides Sub g(Optional x As S = Nothing)
Throw New NotImplementedException()
Throw New System.NotImplementedException()
End Sub
End Class")
End Function
......@@ -370,8 +356,7 @@ End Class
Class [|c|]
Inherits b
End Class",
"Imports System
Structure S
"Structure S
End Structure
MustInherit Class b
Public MustOverride Sub g(Optional x As S? = Nothing)
......@@ -379,7 +364,7 @@ End Class
Class c
Inherits b
Public Overrides Sub g(Optional x As S? = Nothing)
Throw New NotImplementedException()
Throw New System.NotImplementedException()
End Sub
End Class")
End Function
......@@ -394,14 +379,13 @@ End Class
Class [|c|]
Inherits b
End Class",
"Imports System
MustInherit Class b
"MustInherit Class b
Public MustOverride Sub g(Optional x As Integer? = Nothing, Optional y As Integer? = 5)
End Class
Class c
Inherits b
Public Overrides Sub g(Optional x As Integer? = Nothing, Optional y As Integer? = 5)
Throw New NotImplementedException()
Throw New System.NotImplementedException()
End Sub
End Class")
End Function
......@@ -417,8 +401,7 @@ End Class
Class [|c|]
Inherits b
End Class",
"Imports System
Class S
"Class S
End Class
MustInherit Class b
Public MustOverride Sub g(Optional x As S = Nothing)
......@@ -426,7 +409,7 @@ End Class
Class c
Inherits b
Public Overrides Sub g(Optional x As S = Nothing)
Throw New NotImplementedException()
Throw New System.NotImplementedException()
End Sub
End Class")
End Function
......@@ -481,14 +464,13 @@ End Class
Class [|C(Of S)|]
Inherits A(Of S)
End Class",
"Imports System
MustInherit Class A(Of T)
"MustInherit Class A(Of T)
MustOverride Sub Foo(Of S As T)()
End Class
Class C(Of S)
Inherits A(Of S)
Public Overrides Sub Foo(Of S1 As S)()
Throw New NotImplementedException()
Throw New System.NotImplementedException()
End Sub
End Class")
End Function
......
......@@ -49,7 +49,7 @@ internal partial class ImplementInterfaceCodeAction
if (ThroughMember == null)
{
var factory = this.Document.GetLanguageService<SyntaxGenerator>();
return factory.CreateThrowNotImplementStatement(compilation);
return factory.CreateThrowNotImplementedStatement(compilation);
}
else
{
......
......@@ -43,6 +43,11 @@ protected AbstractImportsAdder(Document document)
{
cancellationToken.ThrowIfCancellationRequested();
if (annotatedNode.GetAnnotations(DoNotAddImportsAnnotation.Kind).Any())
{
continue;
}
SyntaxNode namespaceScope = null;
var annotations = annotatedNode.GetAnnotations(SymbolAnnotation.Kind);
foreach (var annotation in annotations)
......
......@@ -7,6 +7,7 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Simplification;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Editing
......@@ -1627,6 +1628,19 @@ public SyntaxNode DottedName(string dottedName)
/// </summary>
public abstract SyntaxNode TypeExpression(ITypeSymbol typeSymbol);
/// <summary>
/// Creates an expression that denotes a type. If addImport is false,
/// adds a <see cref="DoNotAddImportsAnnotation"/> which will prevent any
/// imports or usings from being added for the type.
/// </summary>
public SyntaxNode TypeExpression(ITypeSymbol typeSymbol, bool addImport)
{
var expression = TypeExpression(typeSymbol);
return addImport
? expression
: expression.WithAdditionalAnnotations(DoNotAddImportsAnnotation.Annotation);
}
/// <summary>
/// Creates an expression that denotes a special type name.
/// </summary>
......
......@@ -22,6 +22,7 @@ Microsoft.CodeAnalysis.DocumentActiveContextChangedEventArgs.OldActiveContextDoc
Microsoft.CodeAnalysis.DocumentActiveContextChangedEventArgs.Solution.get -> Microsoft.CodeAnalysis.Solution
Microsoft.CodeAnalysis.DocumentActiveContextChangedEventArgs.SourceTextContainer.get -> Microsoft.CodeAnalysis.Text.SourceTextContainer
Microsoft.CodeAnalysis.Editing.SyntaxGenerator.AddSwitchSections(Microsoft.CodeAnalysis.SyntaxNode switchStatement, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.SyntaxNode> switchSections) -> Microsoft.CodeAnalysis.SyntaxNode
Microsoft.CodeAnalysis.Editing.SyntaxGenerator.TypeExpression(Microsoft.CodeAnalysis.ITypeSymbol typeSymbol, bool addImport) -> Microsoft.CodeAnalysis.SyntaxNode
Microsoft.CodeAnalysis.Options.DocumentOptionSet
Microsoft.CodeAnalysis.Options.DocumentOptionSet.GetOption<T>(Microsoft.CodeAnalysis.Options.PerLanguageOption<T> option) -> T
Microsoft.CodeAnalysis.Options.IOption.StorageLocations.get -> System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Options.OptionStorageLocation>
......
......@@ -15,21 +15,21 @@ namespace Microsoft.CodeAnalysis.Shared.Extensions
{
internal static partial class ICodeDefinitionFactoryExtensions
{
public static SyntaxNode CreateThrowNotImplementStatement(
public static SyntaxNode CreateThrowNotImplementedStatement(
this SyntaxGenerator codeDefinitionFactory,
Compilation compilation)
{
return codeDefinitionFactory.ThrowStatement(
codeDefinitionFactory.ObjectCreationExpression(
compilation.NotImplementedExceptionType(),
SpecializedCollections.EmptyList<SyntaxNode>()));
codeDefinitionFactory.ObjectCreationExpression(
codeDefinitionFactory.TypeExpression(compilation.NotImplementedExceptionType(), addImport: false),
SpecializedCollections.EmptyList<SyntaxNode>()));
}
public static IList<SyntaxNode> CreateThrowNotImplementedStatementBlock(
this SyntaxGenerator codeDefinitionFactory,
Compilation compilation)
{
return new[] { CreateThrowNotImplementStatement(codeDefinitionFactory, compilation) };
return new[] { CreateThrowNotImplementedStatement(codeDefinitionFactory, compilation) };
}
public static IList<SyntaxNode> CreateArguments(
......@@ -223,8 +223,10 @@ private static bool TryGetValue(IDictionary<string, ISymbol> dictionary, string
if (overriddenProperty.IsAbstract)
{
var compilation = await document.Project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
getBody = codeFactory.CreateThrowNotImplementStatement(compilation);
setBody = getBody;
var statement = codeFactory.CreateThrowNotImplementedStatement(compilation);
getBody = statement;
setBody = statement;
}
else if (overriddenProperty.IsIndexer() && document.Project.Language == LanguageNames.CSharp)
{
......@@ -361,11 +363,13 @@ private static bool TryGetValue(IDictionary<string, ISymbol> dictionary, string
if (overriddenMethod.IsAbstract)
{
var compilation = await newDocument.Project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
var statement = codeFactory.CreateThrowNotImplementedStatement(compilation);
return CodeGenerationSymbolFactory.CreateMethodSymbol(
overriddenMethod,
accessibility: overriddenMethod.ComputeResultantAccessibility(newContainingType),
modifiers: modifiers,
statements: new[] { codeFactory.CreateThrowNotImplementStatement(compilation) });
statements: new[] { statement });
}
else
{
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Microsoft.CodeAnalysis.Simplification
{
// When applied to a SyntaxNode, prevents AbstractImportsAdder from
// adding imports for this node. Applied alongside SymbolAnnotation
// when a type should be simplified without adding a using for the type.
//
// For example, override completion adds
// void foo() => throw new System.NotImplementedException()
// with a SymbolAnnotation and a DoNotAddImportsAnnotation.
//
// This allows the simplifier to remove the `System.` if
// `using System` is already in the file but prevents the addition
// of `using System` just for the NotImplementedException.
//
// This could have been implemented as an additional bit serialized
// into the `Data` string of SymbolAnnotation. However that would
// require additional substring operations to retrieve SymbolAnnotation
// symbols even in the common case where we don't need to supress
// add imports. This is therefore implemented as a separate annnotation.
internal class DoNotAddImportsAnnotation
{
public static readonly SyntaxAnnotation Annotation = new SyntaxAnnotation(Kind);
public const string Kind = "DoNotAddImports";
}
}
......@@ -395,6 +395,7 @@
<Compile Include="NamingStyles\Serialization\NamingStylePreferences.cs" />
<Compile Include="NamingStyles\Serialization\SymbolSpecification.cs" />
<Compile Include="Shared\Extensions\SolutionExtensions.cs" />
<Compile Include="Simplification\DoNotAddImportsAnnotation.cs" />
<Compile Include="SymbolKey\SymbolKey.AnonymousFunctionOrDelegateSymbolKey.cs" />
<Compile Include="Workspace\Host\TaskScheduler\WorkspaceTaskSchedulerFactory.WorkspaceTaskScheduler.cs" />
<Compile Include="Tags\WellKnownTags.cs" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册