From 48f409be706a9a7c3e713f588fdae368d755fa04 Mon Sep 17 00:00:00 2001 From: Balaji Soundrarajan Date: Fri, 1 May 2015 21:45:11 -0700 Subject: [PATCH] Correct Property for ExplicitlyImplementedCodeElement Fix #2437: Make sure the Code Element for explicitly implemented interface member carry the appropriate properties --- .../Impl/CodeModel/CSharpCodeModelService.cs | 14 +- .../Test/CodeModel/CSharp/CodeEventTests.vb | 124 +++++++++ .../CodeModel/CSharp/CodeFunctionTests.vb | 92 +++++++ .../CodeModel/CSharp/CodePropertyTests.vb | 244 ++++++++++++++++++ 4 files changed, 469 insertions(+), 5 deletions(-) diff --git a/src/VisualStudio/CSharp/Impl/CodeModel/CSharpCodeModelService.cs b/src/VisualStudio/CSharp/Impl/CodeModel/CSharpCodeModelService.cs index 569aae35b25..e8690695a08 100644 --- a/src/VisualStudio/CSharp/Impl/CodeModel/CSharpCodeModelService.cs +++ b/src/VisualStudio/CSharp/Impl/CodeModel/CSharpCodeModelService.cs @@ -59,7 +59,7 @@ internal partial class CSharpCodeModelService : AbstractCodeModelService private static readonly SymbolDisplayFormat s_fullNameFormat = new SymbolDisplayFormat( typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, - memberOptions: SymbolDisplayMemberOptions.IncludeContainingType, + memberOptions: SymbolDisplayMemberOptions.IncludeContainingType | SymbolDisplayMemberOptions.IncludeExplicitInterface, genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters, miscellaneousOptions: SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers); @@ -794,17 +794,21 @@ public override string GetName(SyntaxNode node) case SyntaxKind.DelegateDeclaration: return ((DelegateDeclarationSyntax)node).Identifier.ToString(); case SyntaxKind.MethodDeclaration: - return ((MethodDeclarationSyntax)node).Identifier.ToString(); + return ((MethodDeclarationSyntax)node).ExplicitInterfaceSpecifier?.ToString() + + ((MethodDeclarationSyntax)node).Identifier.ToString(); case SyntaxKind.ConstructorDeclaration: return ((ConstructorDeclarationSyntax)node).Identifier.ToString(); case SyntaxKind.DestructorDeclaration: return "~" + ((DestructorDeclarationSyntax)node).Identifier.ToString(); case SyntaxKind.PropertyDeclaration: - return ((PropertyDeclarationSyntax)node).Identifier.ToString(); + return ((PropertyDeclarationSyntax)node).ExplicitInterfaceSpecifier?.ToString() + + ((PropertyDeclarationSyntax)node).Identifier.ToString(); case SyntaxKind.IndexerDeclaration: - return ((IndexerDeclarationSyntax)node).ThisKeyword.ToString(); + return ((IndexerDeclarationSyntax)node).ExplicitInterfaceSpecifier?.ToString() + + ((IndexerDeclarationSyntax)node).ThisKeyword.ToString(); case SyntaxKind.EventDeclaration: - return ((EventDeclarationSyntax)node).Identifier.ToString(); + return ((EventDeclarationSyntax)node).ExplicitInterfaceSpecifier?.ToString() + + ((EventDeclarationSyntax)node).Identifier.ToString(); case SyntaxKind.Parameter: return ((ParameterSyntax)node).Identifier.ToString(); case SyntaxKind.NamespaceDeclaration: diff --git a/src/VisualStudio/Core/Test/CodeModel/CSharp/CodeEventTests.vb b/src/VisualStudio/Core/Test/CodeModel/CSharp/CodeEventTests.vb index 15ed3534a0c..9d68d06c230 100644 --- a/src/VisualStudio/Core/Test/CodeModel/CSharp/CodeEventTests.vb +++ b/src/VisualStudio/Core/Test/CodeModel/CSharp/CodeEventTests.vb @@ -114,6 +114,38 @@ class C TextPoint(line:=3, lineOffset:=5, absoluteOffset:=15, lineLength:=38))) End Sub + + + Public Sub GetStartPointExplicitlyImplementedEvent() + Dim code = + +delegate void SampleEventHandler(object sender); + +interface I1 +{ + event SampleEventHandler SampleEvent; +} + +class C1 : I1 +{ + event SampleEventHandler $$I1.SampleEvent + { + add + { + } + + remove + { + } + } +} + + + TestGetStartPoint(code, + Part(EnvDTE.vsCMPart.vsCMPartWholeWithAttributes, + TextPoint(line:=10, lineOffset:=5, absoluteOffset:=131, lineLength:=43))) + End Sub + #End Region #Region "GetEndPoint tests" @@ -221,6 +253,38 @@ class C TextPoint(line:=7, lineOffset:=6, absoluteOffset:=96, lineLength:=5))) End Sub + + + Public Sub GetEndPointExplicitlyImplementedEvent() + Dim code = + +delegate void SampleEventHandler(object sender); + +interface I1 +{ + event SampleEventHandler SampleEvent; +} + +class C1 : I1 +{ + event SampleEventHandler $$I1.SampleEvent + { + add + { + } + + remove + { + } + } +} + + + TestGetEndPoint(code, + Part(EnvDTE.vsCMPart.vsCMPartWholeWithAttributes, + TextPoint(line:=19, lineOffset:=6, absoluteOffset:=250, lineLength:=5))) + End Sub + #End Region #Region "Access tests" @@ -333,6 +397,36 @@ class C TestFullName(code, "C.F") End Sub + + + Public Sub FullName_ExplicitlyImplementedEvent() + Dim code = + +delegate void SampleEventHandler(object sender); + +interface I1 +{ + event SampleEventHandler SampleEvent; +} + +class C1 : I1 +{ + event SampleEventHandler $$I1.SampleEvent + { + add + { + } + + remove + { + } + } +} + + + TestFullName(code, "C1.I1.SampleEvent") + End Sub + #End Region #Region "IsPropertyStyleEvent tests" @@ -427,6 +521,36 @@ class C TestName(code, "F") End Sub + + + Public Sub Name_ExplicitlyImplementedEvent() + Dim code = + +delegate void SampleEventHandler(object sender); + +interface I1 +{ + event SampleEventHandler SampleEvent; +} + +class C1 : I1 +{ + event SampleEventHandler $$I1.SampleEvent + { + add + { + } + + remove + { + } + } +} + + + TestName(code, "I1.SampleEvent") + End Sub + #End Region #Region "Type tests" diff --git a/src/VisualStudio/Core/Test/CodeModel/CSharp/CodeFunctionTests.vb b/src/VisualStudio/Core/Test/CodeModel/CSharp/CodeFunctionTests.vb index 53b5e40e495..2d3b9732092 100644 --- a/src/VisualStudio/Core/Test/CodeModel/CSharp/CodeFunctionTests.vb +++ b/src/VisualStudio/Core/Test/CodeModel/CSharp/CodeFunctionTests.vb @@ -28,6 +28,30 @@ class D Part(EnvDTE.vsCMPart.vsCMPartBody, TextPoint(line:=5, lineOffset:=1, absoluteOffset:=65, lineLength:=23))) End Sub + + + + Public Sub GetStartPointExplicitlyImplementedMethod() + Dim code = + +public interface I1 +{ + int f1(); +} + +public class C1 : I1 +{ + int I1.f1$$() + { + return 0; + } +} + + + TestGetStartPoint(code, + Part(EnvDTE.vsCMPart.vsCMPartWholeWithAttributes, + TextPoint(line:=8, lineOffset:=5, absoluteOffset:=67, lineLength:=15))) + End Sub #End Region #Region "Get End Point" @@ -49,6 +73,30 @@ class D Part(EnvDTE.vsCMPart.vsCMPartBody, TextPoint(line:=6, lineOffset:=1, absoluteOffset:=89, lineLength:=5))) End Sub + + + + Public Sub GetEndPointExplicitlyImplementedMethod() + Dim code = + +public interface I1 +{ + int f1(); +} + +public class C1 : I1 +{ + int I1.f1$$() + { + return 0; + } +} + + + TestGetEndPoint(code, + Part(EnvDTE.vsCMPart.vsCMPartWholeWithAttributes, + TextPoint(line:=11, lineOffset:=6, absoluteOffset:=108, lineLength:=5))) + End Sub #End Region #Region "Access tests" @@ -240,6 +288,28 @@ class C TestFullName(code, "C.~C") End Sub + + + Public Sub FullName_ExplicitlyImplementedMethod() + Dim code = + +public interface I1 +{ + int f1(); +} + +public class C1 : I1 +{ + int I1.f1$$() + { + return 0; + } +} + + + TestFullName(code, "C1.I1.f1") + End Sub + #End Region #Region "FunctionKind tests" @@ -405,6 +475,28 @@ class C : B #Region "Name tests" + + + Public Sub Name_ExplicitlyImplementedMethod() + Dim code = + +public interface I1 +{ + int f1(); +} + +public class C1 : I1 +{ + int I1.f1$$() + { + return 0; + } +} + + + TestName(code, "I1.f1") + End Sub + Public Sub Name_Destructor() Dim code = diff --git a/src/VisualStudio/Core/Test/CodeModel/CSharp/CodePropertyTests.vb b/src/VisualStudio/Core/Test/CodeModel/CSharp/CodePropertyTests.vb index e3d72720947..3ac5efbefcc 100644 --- a/src/VisualStudio/Core/Test/CodeModel/CSharp/CodePropertyTests.vb +++ b/src/VisualStudio/Core/Test/CodeModel/CSharp/CodePropertyTests.vb @@ -248,6 +248,69 @@ class C TextPoint(line:=3, lineOffset:=5, absoluteOffset:=15, lineLength:=31))) End Sub + + + Public Sub GetStartPoint_ExplicitlyImplementedIndexer() + Dim code = + +interface I1 +{ + int this[int i] + { get;set; } +} + +class C1 : I1 +{ + int $$I1.this[int i] + { + get + { + return 0; + } + + set + { + } + } +} + + + TestGetStartPoint(code, + Part(EnvDTE.vsCMPart.vsCMPartWholeWithAttributes, + TextPoint(line:=9, lineOffset:=5, absoluteOffset:=76, lineLength:=22))) + End Sub + + + + Public Sub GetStartPoint_ExplicitlyImplementedProperty() + Dim code = + +interface I1 +{ + int Prop1 { get; set; } +} + +class C1 : I1 +{ + int $$I1.Prop1 + { + get + { + return 0; + } + + set + { + } + } +} + + + TestGetStartPoint(code, + Part(EnvDTE.vsCMPart.vsCMPartWholeWithAttributes, + TextPoint(line:=8, lineOffset:=5, absoluteOffset:=67, lineLength:=16))) + End Sub + #End Region #Region "GetEndPoint() tests" @@ -489,6 +552,69 @@ class C TextPoint(line:=13, lineOffset:=6, absoluteOffset:=182, lineLength:=5))) End Sub + + + Public Sub GetEndPoint_ExplicitlyImplementedProperty() + Dim code = + +interface I1 +{ + int Prop1 { get; set; } +} + +class C1 : I1 +{ + int $$I1.Prop1 + { + get + { + return 0; + } + + set + { + } + } +} + + + TestGetEndPoint(code, + Part(EnvDTE.vsCMPart.vsCMPartWholeWithAttributes, + TextPoint(line:=18, lineOffset:=6, absoluteOffset:=178, lineLength:=5))) + End Sub + + + + Public Sub GetEndPoint_ExplicitlyImplementedIndexer() + Dim code = + +interface I1 +{ + int this[int i] + { get;set; } +} + +class C1 : I1 +{ + int $$I1.this[int i] + { + get + { + return 0; + } + + set + { + } + } +} + + + TestGetEndPoint(code, + Part(EnvDTE.vsCMPart.vsCMPartWholeWithAttributes, + TextPoint(line:=19, lineOffset:=6, absoluteOffset:=193, lineLength:=5))) + End Sub + #End Region #Region "FullName tests" @@ -541,6 +667,65 @@ class C TestFullName(code, "C.this") End Sub + + + Public Sub FullName_ExplicitlyImplementedProperty() + Dim code = + +interface I1 +{ + int Prop1 { get; set; } +} + +class C1 : I1 +{ + int $$I1.Prop1 + { + get + { + return 0; + } + + set + { + } + } +} + + + TestFullName(code, "C1.I1.Prop1") + End Sub + + + + Public Sub FullName_ExplicitlyImplementedIndexer() + Dim code = + +interface I1 +{ + int this[int i] + { get;set; } +} + +class C1 : I1 +{ + int $$I1.this[int i] + { + get + { + return 0; + } + + set + { + } + } +} + + + TestFullName(code, "C1.I1.this") + End Sub + #End Region #Region "IsDefault tests" @@ -650,6 +835,65 @@ class C TestName(code, "this") End Sub + + + Public Sub Name_ExplicitlyImplementedProperty() + Dim code = + +interface I1 +{ + int Prop1 { get; set; } +} + +class C1 : I1 +{ + int $$I1.Prop1 + { + get + { + return 0; + } + + set + { + } + } +} + + + TestName(code, "I1.Prop1") + End Sub + + + + Public Sub Name_ExplicitlyImplementedIndexer() + Dim code = + +interface I1 +{ + int this[int i] + { get;set; } +} + +class C1 : I1 +{ + int $$I1.this[int i] + { + get + { + return 0; + } + + set + { + } + } +} + + + TestName(code, "I1.this") + End Sub + #End Region #Region "Prototype tests" -- GitLab