Skip to content

Commit

Permalink
Merge pull request #43 from canhorn/bug/fix_constructor_no_namespace_…
Browse files Browse the repository at this point in the history
…generation

Fixed No Namespace issue found in Accessors, Methods, Properties and constructors.
  • Loading branch information
canhorn authored Apr 22, 2021
2 parents 530ae25 + b95482a commit 0750eb3
Show file tree
Hide file tree
Showing 19 changed files with 317 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
)[[BASE_CLASS_CALL]]
{
var entity = EventHorizonBlazorInterop.New(
new string[] { [[PROPERTY_NAMESPACE]], "[[CLASS_NAME]]" },
new string[] { [[PROPERTY_NAMESPACE]]"[[CLASS_NAME]]" },
[[PROPERTY_ARGUMENTS]]
);
___guid = entity.___guid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ClassGenerationTemplates templates
var entityNamespace = string.Join(
", ",
namespaceParts.Select(part => @$"""{part}""")
);
) + ", ";
var property = accessor.Name;
var propertyGetterTemplate = templates.ReturnTypePrimitiveTemplate;
var cacheSection = string.Empty;
Expand All @@ -57,6 +57,11 @@ ClassGenerationTemplates templates
template = templates.AccessorWithSetter;
}

if (entityNamespace == @""""", ")
{
entityNamespace = string.Empty;
}

if (accessor.IsStatic)
{
root = $"\"{namespaceParts.FirstOrDefault()}\"";
Expand All @@ -73,10 +78,15 @@ ClassGenerationTemplates templates
else
{
property = $"{classStatement.Name}.{accessor.Name}";
if (entityNamespace == string.Empty)
{
root = $"\"{classStatement.Name}\"";
property = accessor.Name;
}
}
}

if(isEnum)
if (isEnum)
{
propertyGetterResultType = templates.InteropGet;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ ClassGenerationTemplates templates
classStatement.Namespace
.Split(".")
.Select(part => @$"""{part}""")
);
) + ", ";

if (entityNamespace == @""""", ")
{
entityNamespace = string.Empty;
}

return template.Replace(
"[[CLASS_NAME]]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ ClassGenerationTemplates templates
var returnTypeContent = templates.InteropFunc;
var arguments = string.Empty;
var argumentStrings = new List<string>();
var classNamespace = classStatement.Namespace;
var namespacedMethod = string.Join(
".",
classStatement.Namespace,
classNamespace,
classStatement.Name,
method.Name
);
Expand All @@ -78,6 +79,15 @@ ClassGenerationTemplates templates
var taskAsync = string.Empty;
var taskAwait = string.Empty;

if (classNamespace == string.Empty)
{
namespacedMethod = string.Join(
".",
classStatement.Name,
method.Name
);
}

// Argument Generation
if (isAction)
{
Expand Down Expand Up @@ -223,12 +233,22 @@ ClassGenerationTemplates templates

if (method.IsStatic)
{
var classStatementIdentitiferList = new string[] {
classStatement.Name,
};
if (classNamespace != string.Empty)
{
classStatementIdentitiferList = new string[]
{
classStatement.Namespace,
classStatement.Name,
};
}
propertyIdentifier = string.Join(
", ",
string.Join(
".",
classStatement.Namespace,
classStatement.Name
classStatementIdentitiferList
).Split(".").Select(part => @$"""{part}""")
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ ClassGenerationTemplates templates
var entityNamespace = string.Join(
", ",
namespaceParts.Select(part => @$"""{part}""")
);
) + ", ";
var propertyIdentifier = property.Name;
var propertyGetterTemplate = templates.ReturnTypePrimitiveTemplate;
var cacheSection = string.Empty;
Expand All @@ -63,6 +63,11 @@ ClassGenerationTemplates templates
template = templates.Accessor;
}

if (entityNamespace == @""""", ")
{
entityNamespace = string.Empty;
}

if (property.IsStatic)
{

Expand All @@ -80,6 +85,11 @@ ClassGenerationTemplates templates
else
{
propertyIdentifier = $"{classStatement.Name}.{property.Name}";
if (entityNamespace == string.Empty)
{
root = $"\"{classStatement.Name}\"";
propertyIdentifier = property.Name;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
)
{
var entity = await EventHorizonBlazorInterop.New(
new string[] { [[PROPERTY_NAMESPACE]], "[[CLASS_NAME]]" },
new string[] { [[PROPERTY_NAMESPACE]]"[[CLASS_NAME]]" },
[[PROPERTY_ARGUMENTS]]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public class CSharpTextClass : CachedEntityObject

public CSharpTextClass(object target = null)
{
var entity = EventHorizonBlazorInterop.New(new string[]{"", "CSharpTextClass"}, target);
var entity = EventHorizonBlazorInterop.New(new string[]{"CSharpTextClass"}, target);
___guid = entity.___guid;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/// Generated - Do Not Edit
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using EventHorizon.Blazor.Interop;
using EventHorizon.Blazor.Interop.Callbacks;
using Microsoft.JSInterop;



[JsonConverter(typeof(CachedEntityConverter<ExampleClass>))]
public class ExampleClass : CachedEntityObject
{
#region Static Accessors

public static decimal Now
{
get
{
return EventHorizonBlazorInterop.Get<decimal>(
"ExampleClass",
"Now"
);
}
}
#endregion

#region Static Properties

#endregion

#region Static Methods

#endregion

#region Accessors

#endregion

#region Properties

#endregion

#region Constructor
public ExampleClass() : base() { }

public ExampleClass(
ICachedEntity entity
) : base(entity)
{
___guid = entity.___guid;
}


#endregion

#region Methods

#endregion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export class ExampleClass {
static get Now(): number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ ASTParserType parserType
[InlineData("InterfaceResponse.ts", "Accessors", "Scenarios", "InterfaceResponse.Expected.txt", ASTParserType.Sdcb)]
[InlineData("NamespacedTyping.ts", "Accessors", "Scenarios", "NamespacedTyping.Expected.txt", ASTParserType.Sdcb)]
[InlineData("NullableTyping.ts", "Accessors", "Scenarios", "NullableTyping.Expected.txt", ASTParserType.Sdcb)]
[InlineData("StaticNoNamespace.d.ts", "Accessors", "Scenarios", "StaticNoNamespace.d.Expected.txt", ASTParserType.Sdcb)]
[InlineData("StaticRootNamespace.ts", "Accessors", "Scenarios", "StaticRootNamespace.Expected.txt", ASTParserType.Sdcb)]
public void ShouldGenerateAccessorScenarioStringsWithSdcb(
string sourceFile,
Expand Down Expand Up @@ -117,6 +118,7 @@ ASTParserType parserType
[InlineData("InterfaceResponse.ts", "Accessors", "Scenarios", "InterfaceResponse.Expected.txt", ASTParserType.NodeJS)]
[InlineData("NamespacedTyping.ts", "Accessors", "Scenarios", "NamespacedTyping.Expected.txt", ASTParserType.NodeJS)]
[InlineData("NullableTyping.ts", "Accessors", "Scenarios", "NullableTyping.Expected.txt", ASTParserType.NodeJS)]
[InlineData("StaticNoNamespace.d.ts", "Accessors", "Scenarios", "StaticNoNamespace.d.Expected.txt", ASTParserType.NodeJS)]
[InlineData("StaticRootNamespace.ts", "Accessors", "Scenarios", "StaticRootNamespace.Expected.txt", ASTParserType.NodeJS)]
public void ShouldGenerateAccessorScenarioStringsWithNodeJS(
string sourceFile,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/// Generated - Do Not Edit
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using EventHorizon.Blazor.Interop;
using EventHorizon.Blazor.Interop.Callbacks;
using Microsoft.JSInterop;



[JsonConverter(typeof(CachedEntityConverter<ExampleClass>))]
public class ExampleClass : CachedEntityObject
{
#region Static Accessors

#endregion

#region Static Properties

#endregion

#region Static Methods

#endregion

#region Accessors

#endregion

#region Properties

#endregion

#region Constructor
public ExampleClass() : base() { }

public ExampleClass(
ICachedEntity entity
) : base(entity)
{
___guid = entity.___guid;
}

public ExampleClass(
string arg1
)
{
var entity = EventHorizonBlazorInterop.New(
new string[] { "ExampleClass" },
arg1
);
___guid = entity.___guid;
}
#endregion

#region Methods

#endregion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export class ExampleClass {
constructor(arg1: string);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ ASTParserType parserType
[InlineData("MethodStaticClassWithNullArgument.ts", "Methods", "Scenarios", "MethodStaticClassWithNullArgument.Expected.txt", ASTParserType.Sdcb)]
[InlineData("MethodStaticClassWithUndefinedArgument.ts", "Methods", "Scenarios", "MethodStaticClassWithUndefinedArgument.Expected.txt", ASTParserType.Sdcb)]
[InlineData("MethodStaticWithLiteralAsResult.ts", "Methods", "Scenarios", "MethodStaticWithLiteralAsResult.Expected.txt", ASTParserType.Sdcb)]
[InlineData("StaticNoNamespace.d.ts", "Methods", "Scenarios", "StaticNoNamespace.d.Expected.txt", ASTParserType.Sdcb)]
public void ShouldGenerateStaticMethodScenarioStringsUsingSdcb(
string sourceFile,
string rootPath,
Expand Down Expand Up @@ -126,6 +127,7 @@ ASTParserType parserType
[InlineData("MethodStaticClassWithNullArgument.ts", "Methods", "Scenarios", "MethodStaticClassWithNullArgument.Expected.txt", ASTParserType.NodeJS)]
[InlineData("MethodStaticClassWithUndefinedArgument.ts", "Methods", "Scenarios", "MethodStaticClassWithUndefinedArgument.Expected.txt", ASTParserType.NodeJS)]
[InlineData("MethodStaticWithLiteralAsResult.ts", "Methods", "Scenarios", "MethodStaticWithLiteralAsResult.Expected.txt", ASTParserType.NodeJS)]
[InlineData("StaticNoNamespace.d.ts", "Methods", "Scenarios", "StaticNoNamespace.d.Expected.txt", ASTParserType.NodeJS)]
public void ShouldGenerateStaticMethodScenarioStringsUsingNodeJS(
string sourceFile,
string rootPath,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/// Generated - Do Not Edit
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using EventHorizon.Blazor.Interop;
using EventHorizon.Blazor.Interop.Callbacks;
using Microsoft.JSInterop;



[JsonConverter(typeof(CachedEntityConverter<ExampleClass>))]
public class ExampleClass : CachedEntityObject
{
#region Static Accessors

#endregion

#region Static Properties

#endregion

#region Static Methods
public static decimal numberMethod()
{
return EventHorizonBlazorInterop.Func<decimal>(
new object[]
{
new string[] { "ExampleClass", "numberMethod" }
}
);
}
#endregion

#region Accessors

#endregion

#region Properties

#endregion

#region Constructor
public ExampleClass() : base() { }

public ExampleClass(
ICachedEntity entity
) : base(entity)
{
___guid = entity.___guid;
}


#endregion

#region Methods

#endregion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export class ExampleClass {
static numberMethod(): number;
}
Loading

0 comments on commit 0750eb3

Please sign in to comment.