From b4baba7b0f5b7ea689ca768571cfd94242045d54 Mon Sep 17 00:00:00 2001 From: Pavel Novikov Date: Thu, 7 Dec 2017 04:29:28 +0700 Subject: [PATCH] 1.4.2 --- .../Reinforced.Typings.Tests.csproj | 2 + ...pecificTestCases.NestedClassInheritance.cs | 59 +++++++++++++++++++ ...icTestCases.OverridenNamesNotCamelCased.cs | 48 +++++++++++++++ .../Generators/MethodCodeGenerator.cs | 16 +++-- .../Generators/PropertyCodeGenerator.cs | 22 ++++--- package/Reinforced.Typings.nuspec | 1 + 6 files changed, 136 insertions(+), 12 deletions(-) create mode 100644 Reinforced.Typings.Tests/SpecificCases/SpecificTestCases.NestedClassInheritance.cs create mode 100644 Reinforced.Typings.Tests/SpecificCases/SpecificTestCases.OverridenNamesNotCamelCased.cs diff --git a/Reinforced.Typings.Tests/Reinforced.Typings.Tests.csproj b/Reinforced.Typings.Tests/Reinforced.Typings.Tests.csproj index ce46e1ab..a6b7db9d 100644 --- a/Reinforced.Typings.Tests/Reinforced.Typings.Tests.csproj +++ b/Reinforced.Typings.Tests/Reinforced.Typings.Tests.csproj @@ -82,6 +82,8 @@ + + diff --git a/Reinforced.Typings.Tests/SpecificCases/SpecificTestCases.NestedClassInheritance.cs b/Reinforced.Typings.Tests/SpecificCases/SpecificTestCases.NestedClassInheritance.cs new file mode 100644 index 00000000..2010d662 --- /dev/null +++ b/Reinforced.Typings.Tests/SpecificCases/SpecificTestCases.NestedClassInheritance.cs @@ -0,0 +1,59 @@ +using Reinforced.Typings.Fluent; +using Xunit; + +namespace TestA +{ + public class TestParentClassA + { + public string Id { get; set; } + public string Name { get; set; } + } + +} + +namespace TestB +{ + using TestA; + public class SomeOtherClass + { + public class SomeDerivedClass : TestParentClassA + { + public int OtherId { get; set; } + } + } +} + +namespace Reinforced.Typings.Tests.SpecificCases +{ + + public partial class SpecificTestCases + { + [Fact] + public void NestedClassInheritance() + { + const string result = @" +module TestB { + export interface ISomeDerivedClass extends TestB.ITestParentClassA + { + OtherId: number; + } + export interface ITestParentClassA + { + id: string; + text: string; + } +} +"; + AssertConfiguration(s => + { + s.Global(a => a.DontWriteWarningComment()); + s.ExportAsInterface() + .WithPublicProperties(); + s.ExportAsInterface() + .WithProperty(c => c.Id, v => v.OverrideName("id")) + .WithProperty(c => c.Name, v => v.OverrideName("text")) + .OverrideNamespace("TestB"); + }, result); + } + } +} \ No newline at end of file diff --git a/Reinforced.Typings.Tests/SpecificCases/SpecificTestCases.OverridenNamesNotCamelCased.cs b/Reinforced.Typings.Tests/SpecificCases/SpecificTestCases.OverridenNamesNotCamelCased.cs new file mode 100644 index 00000000..35e1cd6b --- /dev/null +++ b/Reinforced.Typings.Tests/SpecificCases/SpecificTestCases.OverridenNamesNotCamelCased.cs @@ -0,0 +1,48 @@ +using Reinforced.Typings.Attributes; +using Reinforced.Typings.Fluent; +using Xunit; + +namespace Reinforced.Typings.Tests.SpecificCases +{ + public class TestOverrides + { + [TsProperty(Name = "ID", ForceNullable = true)] + public virtual int _id { get { return 0; } } + + [TsFunction(Name = "DO_DOMETHING")] + public void DoSomething() { } + + public void AnotherMethod() { } + + public string AnotherProeprty { get; set; } + } + public partial class SpecificTestCases + { + + + [Fact] + public void OverridenNamesNotCamelCased() + { + const string result = @" +module Reinforced.Typings.Tests.SpecificCases { + export interface ITestOverrides + { + ID?: number; + Another_Property: string; + DO_DOMETHING() : void; + Another_Method() : void; + } +}"; + AssertConfiguration(s => + { + s.Global(a => a.DontWriteWarningComment().CamelCaseForMethods().CamelCaseForProperties()); + s.ExportAsInterface() + .WithPublicProperties() + .WithPublicMethods() + .WithMethod(x=>x.AnotherMethod(),x=>x.OverrideName("Another_Method")) + .WithProperty(x=>x.AnotherProeprty,x=>x.OverrideName("Another_Property")) + ; + }, result); + } + } +} \ No newline at end of file diff --git a/Reinforced.Typings/Generators/MethodCodeGenerator.cs b/Reinforced.Typings/Generators/MethodCodeGenerator.cs index 9e887d5e..b2643c6d 100644 --- a/Reinforced.Typings/Generators/MethodCodeGenerator.cs +++ b/Reinforced.Typings/Generators/MethodCodeGenerator.cs @@ -83,11 +83,16 @@ public override RtFuncion GenerateNode(MethodInfo element, RtFuncion result, Typ protected virtual void GetFunctionNameAndReturnType(MethodInfo element, TypeResolver resolver, out string name, out RtTypeName type) { name = element.Name; + bool isNameOverridden = false; var fa = ConfigurationRepository.Instance.ForMember(element); if (fa != null) { - if (!string.IsNullOrEmpty(fa.Name)) name = fa.Name; + if (!string.IsNullOrEmpty(fa.Name)) + { + name = fa.Name; + isNameOverridden = true; + } if (!string.IsNullOrEmpty(fa.Type)) type = new RtSimpleTypeName(fa.Type); else if (fa.StrongType != null) type = resolver.ResolveTypeName(fa.StrongType); @@ -99,9 +104,12 @@ protected virtual void GetFunctionNameAndReturnType(MethodInfo element, TypeReso type = resolver.ResolveTypeName(element.ReturnType); } - name = Context.ConditionallyConvertMethodNameToCamelCase(name); - name = element.CamelCaseFromAttribute(name); - name = element.PascalCaseFromAttribute(name); + if (!isNameOverridden) + { + name = Context.ConditionallyConvertMethodNameToCamelCase(name); + name = element.CamelCaseFromAttribute(name); + name = element.PascalCaseFromAttribute(name); + } if (element.IsGenericMethod) { if (!(name.Contains("<") || name.Contains(">"))) diff --git a/Reinforced.Typings/Generators/PropertyCodeGenerator.cs b/Reinforced.Typings/Generators/PropertyCodeGenerator.cs index d293c11b..4757315c 100644 --- a/Reinforced.Typings/Generators/PropertyCodeGenerator.cs +++ b/Reinforced.Typings/Generators/PropertyCodeGenerator.cs @@ -34,7 +34,7 @@ public override RtField GenerateNode(MemberInfo element, RtField result, TypeRes var t = GetType(element); RtTypeName type = null; var propName = new RtIdentifier(element.Name); - + bool isNameOverridden = false; var tp = ConfigurationRepository.Instance.ForMember(element); if (tp != null) { @@ -49,7 +49,11 @@ public override RtField GenerateNode(MemberInfo element, RtField result, TypeRes type = tp.TypeInferers.Infer(element, resolver) ?? type; - if (!string.IsNullOrEmpty(tp.Name)) propName.IdentifierName = tp.Name; + if (!string.IsNullOrEmpty(tp.Name)) + { + propName.IdentifierName = tp.Name; + isNameOverridden = true; + } if (tp.NilForceNullable.HasValue && !Context.SpecialCase) { propName.IsNullable = tp.NilForceNullable.Value; @@ -64,14 +68,16 @@ public override RtField GenerateNode(MemberInfo element, RtField result, TypeRes propName.IsNullable = true; } } - - if (element is PropertyInfo) + if (!isNameOverridden) { - propName.IdentifierName = Context.ConditionallyConvertPropertyNameToCamelCase(propName.IdentifierName); + if (element is PropertyInfo) + { + propName.IdentifierName = + Context.ConditionallyConvertPropertyNameToCamelCase(propName.IdentifierName); + } + propName.IdentifierName = element.CamelCaseFromAttribute(propName.IdentifierName); + propName.IdentifierName = element.PascalCaseFromAttribute(propName.IdentifierName); } - propName.IdentifierName = element.CamelCaseFromAttribute(propName.IdentifierName); - propName.IdentifierName = element.PascalCaseFromAttribute(propName.IdentifierName); - result.Identifier = propName; result.AccessModifier = Context.SpecialCase ? AccessModifier.Public : element.GetModifier(); result.Type = type; diff --git a/package/Reinforced.Typings.nuspec b/package/Reinforced.Typings.nuspec index 4db4bb50..c934e6b5 100644 --- a/package/Reinforced.Typings.nuspec +++ b/package/Reinforced.Typings.nuspec @@ -17,6 +17,7 @@ https://github.com/reinforced/Reinforced.Typings/blob/master/LICENSE.md - Additional assemblies resolvation fix +- Explicitly overriden names are no more subjects of casing change