Skip to content

Commit

Permalink
1.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-b-novikov committed Dec 6, 2017
1 parent aa776e4 commit b4baba7
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 12 deletions.
2 changes: 2 additions & 0 deletions Reinforced.Typings.Tests/Reinforced.Typings.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
<Compile Include="SpecificCases\SpecificTestCases.RluitenConstEnums.cs" />
<Compile Include="SpecificCases\SpecificTestCases.TsFunctionWorks.cs" />
<Compile Include="SpecificCases\SpecificTestCases.TsPropertyWorks.cs" />
<Compile Include="SpecificCases\SpecificTestCases.OverridenNamesNotCamelCased.cs" />
<Compile Include="SpecificCases\SpecificTestCases.NestedClassInheritance.cs" />
<Compile Include="SpecificCases\SpecificTestCases._CopyMe_.cs" />
<Compile Include="SpecificCases\SpecificTestCases.JonsaEnumWithouNamespaceTest.cs" />
<Compile Include="SpecificCases\SpecificTestCases.PandaWoodCamelCase.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -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<TestB.SomeOtherClass.SomeDerivedClass>()
.WithPublicProperties();
s.ExportAsInterface<TestA.TestParentClassA>()
.WithProperty(c => c.Id, v => v.OverrideName("id"))
.WithProperty(c => c.Name, v => v.OverrideName("text"))
.OverrideNamespace("TestB");
}, result);
}
}
}
Original file line number Diff line number Diff line change
@@ -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<TestOverrides>()
.WithPublicProperties()
.WithPublicMethods()
.WithMethod(x=>x.AnotherMethod(),x=>x.OverrideName("Another_Method"))
.WithProperty(x=>x.AnotherProeprty,x=>x.OverrideName("Another_Property"))
;
}, result);
}
}
}
16 changes: 12 additions & 4 deletions Reinforced.Typings/Generators/MethodCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(">")))
Expand Down
22 changes: 14 additions & 8 deletions Reinforced.Typings/Generators/PropertyCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TsPropertyAttribute>(element);
if (tp != null)
{
Expand All @@ -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;
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions package/Reinforced.Typings.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<licenseUrl>https://github.com/reinforced/Reinforced.Typings/blob/master/LICENSE.md</licenseUrl>
<releaseNotes>
- Additional assemblies resolvation fix
- Explicitly overriden names are no more subjects of casing change
</releaseNotes>
<dependencies>
<group targetFramework=".NETFramework4.5" />
Expand Down

0 comments on commit b4baba7

Please sign in to comment.