From 5283488d7cd31f06e21c5793f9f844b32b817519 Mon Sep 17 00:00:00 2001 From: Andrei Fangli Date: Fri, 7 Jul 2023 14:13:15 +0300 Subject: [PATCH] Removed declaring type from declaration node simple name --- ...eExtensions_GetSimpleNameReferenceTests.cs | 28 +++---- .../Html/SimpleNameDeclarationNodeVisitor.cs | 75 ++----------------- 2 files changed, 19 insertions(+), 84 deletions(-) diff --git a/CodeMap.Tests/Html/DeclarationNodeExtensions_GetSimpleNameReferenceTests.cs b/CodeMap.Tests/Html/DeclarationNodeExtensions_GetSimpleNameReferenceTests.cs index 9208ca41..6b08a88a 100644 --- a/CodeMap.Tests/Html/DeclarationNodeExtensions_GetSimpleNameReferenceTests.cs +++ b/CodeMap.Tests/Html/DeclarationNodeExtensions_GetSimpleNameReferenceTests.cs @@ -134,7 +134,7 @@ public void GettingSimpleNameReferenceForConstantDeclarationReturnsDeclaringType var simpleNameReference = constantDeclaration.GetSimpleNameReference(); - Assert.Equal("TestClass.ClassShadowedTestConstant", simpleNameReference); + Assert.Equal("ClassShadowedTestConstant", simpleNameReference); } [Fact] @@ -152,7 +152,7 @@ public void GettingSimpleNameReferenceForFieldDeclarationReturnsDeclaringTypeNam var simpleNameReference = fieldDeclaration.GetSimpleNameReference(); - Assert.Equal("TestClass.StaticTestField", simpleNameReference); + Assert.Equal("StaticTestField", simpleNameReference); } [Fact] @@ -170,7 +170,7 @@ public void GettingSimpleNameReferenceForConstructorDeclarationReturnsDeclaringT var simpleNameReference = constructorDeclaration.GetSimpleNameReference(); - Assert.Equal("TestClass.TestClass(int)", simpleNameReference); + Assert.Equal("TestClass(int)", simpleNameReference); } [Fact] @@ -188,7 +188,7 @@ public void GettingSimpleNameReferenceForEventDeclarationReturnsDeclaringTypeNam var simpleNameReference = eventDeclaration.GetSimpleNameReference(); - Assert.Equal("TestClass.AbstractTestEvent", simpleNameReference); + Assert.Equal("AbstractTestEvent", simpleNameReference); } [Fact] @@ -206,7 +206,7 @@ public void GettingSimpleNameReferenceForPropertyDeclarationReturnsDeclaringType var simpleNameReference = propertyDeclaration.GetSimpleNameReference(); - Assert.Equal("TestClass.InterfaceShadowedTestProperty", simpleNameReference); + Assert.Equal("InterfaceShadowedTestProperty", simpleNameReference); } [Fact] @@ -224,7 +224,7 @@ public void GettingSimpleNameReferenceForIndexPropertyDeclarationReturnsDeclarin var simpleNameReference = propertyDeclaration.GetSimpleNameReference(); - Assert.Equal("TestClass.Item[int]", simpleNameReference); + Assert.Equal("Item[int]", simpleNameReference); } [Fact] @@ -242,7 +242,7 @@ public void GettingSimpleNameReferenceForMethodDeclarationReturnsDeclaringTypeNa var simpleNameReference = methodDeclaration.GetSimpleNameReference(); - Assert.Equal("TestClass.TestMethod(int, string)", simpleNameReference); + Assert.Equal("TestMethod(int, string)", simpleNameReference); } [Fact] @@ -260,7 +260,7 @@ public void GettingSimpleNameReferenceForGenericMethodDeclarationReturnsDeclarin var simpleNameReference = methodDeclaration.GetSimpleNameReference(); - Assert.Equal("TestClass.TestMethod38(TMethodParam)", simpleNameReference); + Assert.Equal("TestMethod38(TMethodParam)", simpleNameReference); } [Fact] @@ -278,7 +278,7 @@ public void GettingSimpleNameReferenceForNestedEnumReturnsDeclaringTypeNameAndOw var simpleNameReference = typeDeclaration.GetSimpleNameReference(); - Assert.Equal("TestClass.NestedTestEnum", simpleNameReference); + Assert.Equal("NestedTestEnum", simpleNameReference); } [Fact] @@ -296,7 +296,7 @@ public void GettingSimpleNameReferenceForNestedDelegateReturnsDeclaringTypeNameO var simpleNameReference = typeDeclaration.GetSimpleNameReference(); - Assert.Equal("TestClass.NestedTestDelegate()", simpleNameReference); + Assert.Equal("NestedTestDelegate()", simpleNameReference); } [Fact] @@ -314,7 +314,7 @@ public void GettingSimpleNameReferenceForNestedInterfaceReturnsDeclaringTypeName var simpleNameReference = typeDeclaration.GetSimpleNameReference(); - Assert.Equal("TestClass.INestedTestInterface", simpleNameReference); + Assert.Equal("INestedTestInterface", simpleNameReference); } [Fact] @@ -332,7 +332,7 @@ public void GettingSimpleNameReferenceForNestedInterfaceReturnsDeclaringTypeName var simpleNameReference = typeDeclaration.GetSimpleNameReference(); - Assert.Equal("TestClass.NestedTestClass", simpleNameReference); + Assert.Equal("NestedTestClass", simpleNameReference); } [Fact] @@ -350,7 +350,7 @@ public void GettingSimpleNameReferenceForNestedRecordReturnsDeclaringTypeNameAnd var simpleNameReference = typeDeclaration.GetSimpleNameReference(); - Assert.Equal("TestClass.NestedTestRecord", simpleNameReference); + Assert.Equal("NestedTestRecord", simpleNameReference); } [Fact] @@ -368,7 +368,7 @@ public void GettingSimpleNameReferenceForNestedStructReturnsDeclaringTypeNameAnd var simpleNameReference = typeDeclaration.GetSimpleNameReference(); - Assert.Equal("TestClass.NestedTestStruct", simpleNameReference); + Assert.Equal("NestedTestStruct", simpleNameReference); } } } \ No newline at end of file diff --git a/CodeMap/Html/SimpleNameDeclarationNodeVisitor.cs b/CodeMap/Html/SimpleNameDeclarationNodeVisitor.cs index 5ebbd5a3..938c0380 100644 --- a/CodeMap/Html/SimpleNameDeclarationNodeVisitor.cs +++ b/CodeMap/Html/SimpleNameDeclarationNodeVisitor.cs @@ -1,4 +1,3 @@ -using System.Data; using System.Linq; using System.Text; using CodeMap.DeclarationNodes; @@ -10,9 +9,7 @@ internal class SimpleNameDeclarationNodeVisitor : DeclarationNodeVisitor public StringBuilder StringBuilder { get; } = new StringBuilder(); protected internal override void VisitAssembly(AssemblyDeclaration assembly) - { - StringBuilder.Append(assembly.Name); - } + => StringBuilder.Append(assembly.Name); protected internal override void VisitNamespace(NamespaceDeclaration @namespace) { @@ -22,12 +19,6 @@ protected internal override void VisitNamespace(NamespaceDeclaration @namespace) protected internal override void VisitInterface(InterfaceDeclaration @interface) { - if (@interface.DeclaringType is object) - { - @interface.DeclaringType.Accept(this); - StringBuilder.Append('.'); - } - StringBuilder.Append(@interface.Name); if (@interface.GenericParameters.Any()) @@ -48,12 +39,6 @@ protected internal override void VisitInterface(InterfaceDeclaration @interface) protected internal override void VisitClass(ClassDeclaration @class) { - if (@class.DeclaringType is object) - { - @class.DeclaringType.Accept(this); - StringBuilder.Append('.'); - } - StringBuilder.Append(@class.Name); if (@class.GenericParameters.Any()) { @@ -73,12 +58,6 @@ protected internal override void VisitClass(ClassDeclaration @class) protected internal override void VisitRecord(RecordDeclaration record) { - if (record.DeclaringType is object) - { - record.DeclaringType.Accept(this); - StringBuilder.Append('.'); - } - StringBuilder.Append(record.Name); if (record.GenericParameters.Any()) { @@ -98,12 +77,6 @@ protected internal override void VisitRecord(RecordDeclaration record) protected internal override void VisitStruct(StructDeclaration @struct) { - if (@struct.DeclaringType is object) - { - @struct.DeclaringType.Accept(this); - StringBuilder.Append('.'); - } - StringBuilder.Append(@struct.Name); if (@struct.GenericParameters.Any()) { @@ -123,12 +96,6 @@ protected internal override void VisitStruct(StructDeclaration @struct) protected internal override void VisitDelegate(DelegateDeclaration @delegate) { - if (@delegate.DeclaringType is object) - { - @delegate.DeclaringType.Accept(this); - StringBuilder.Append('.'); - } - StringBuilder.Append(@delegate.Name); if (@delegate.GenericParameters.Any()) { @@ -161,37 +128,16 @@ protected internal override void VisitDelegate(DelegateDeclaration @delegate) } protected internal override void VisitEnum(EnumDeclaration @enum) - { - if (@enum.DeclaringType is object) - { - @enum.DeclaringType.Accept(this); - StringBuilder.Append('.'); - } - - StringBuilder.Append(@enum.Name); - } + => StringBuilder.Append(@enum.Name); protected internal override void VisitConstant(ConstantDeclaration constant) - { - constant.DeclaringType.Accept(this); - StringBuilder.Append('.'); - - StringBuilder.Append(constant.Name); - } + => StringBuilder.Append(constant.Name); protected internal override void VisitField(FieldDeclaration field) - { - field.DeclaringType.Accept(this); - StringBuilder.Append('.'); - - StringBuilder.Append(field.Name); - } + => StringBuilder.Append(field.Name); protected internal override void VisitConstructor(ConstructorDeclaration constructor) { - constructor.DeclaringType.Accept(this); - StringBuilder.Append('.'); - StringBuilder.Append(constructor.Name); StringBuilder.Append('('); var isFirst = true; @@ -207,18 +153,10 @@ protected internal override void VisitConstructor(ConstructorDeclaration constru } protected internal override void VisitEvent(EventDeclaration @event) - { - @event.DeclaringType.Accept(this); - StringBuilder.Append('.'); - - StringBuilder.Append(@event.Name); - } + => StringBuilder.Append(@event.Name); protected internal override void VisitProperty(PropertyDeclaration property) { - property.DeclaringType.Accept(this); - StringBuilder.Append('.'); - StringBuilder.Append(property.Name); if (property.Parameters.Any()) { @@ -238,9 +176,6 @@ protected internal override void VisitProperty(PropertyDeclaration property) protected internal override void VisitMethod(MethodDeclaration method) { - method.DeclaringType.Accept(this); - StringBuilder.Append('.'); - StringBuilder.Append(method.Name); if (method.GenericParameters.Any()) {