Skip to content

Commit

Permalink
Fixed No Namespace issue found in Accessors, Methods, Properties and …
Browse files Browse the repository at this point in the history
…constructors.
  • Loading branch information
canhorn committed Apr 22, 2021
1 parent 894823a commit b95482a
Show file tree
Hide file tree
Showing 19 changed files with 198 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ string source
).GetAwaiter().GetResult();

// Use for testing the generated AST
File.WriteAllText(
Path.Combine(
".",
"AstParser",
"NodeImpl",
"NodeJS",
"_generated",
"ast.json"
),
result
);
//File.WriteAllText(
// Path.Combine(
// ".",
// "AstParser",
// "NodeImpl",
// "NodeJS",
// "_generated",
// "ast.json"
// ),
// result
//);
var ast = JsonSerializer.Deserialize<ASTModel>(
result,
new JsonSerializerOptions
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,6 +78,11 @@ ClassGenerationTemplates templates
else
{
property = $"{classStatement.Name}.{accessor.Name}";
if (entityNamespace == string.Empty)
{
root = $"\"{classStatement.Name}\"";
property = accessor.Name;
}
}
}

Expand All @@ -96,11 +106,6 @@ ClassGenerationTemplates templates
propertyGetterResultType = templates.InteropGetArray;
}

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

template = template
.Replace(
"[[PROPERTY_GETTER]]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ ClassGenerationTemplates templates
classStatement.Namespace
.Split(".")
.Select(part => @$"""{part}""")
);
) + ", ";

if (entityNamespace == @"""""")
if (entityNamespace == @""""", ")
{
entityNamespace = string.Empty;
}
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 Expand Up @@ -116,11 +126,6 @@ ClassGenerationTemplates templates
template = "// [[NAME]] is not supported by the platform yet";
}

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

template = template
.Replace(
"[[PROPERTY_GETTER]]",
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
Expand Up @@ -51,6 +51,8 @@ public class ExampleClass : CachedEntityObject
{
___guid = entity.___guid;
}


#endregion

#region Methods
Expand Down
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,3 @@
export class ExampleClass {
constructor(arg1: string);
}

This file was deleted.

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;
}
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

#endregion

#region Static Properties

public static decimal NoneLogLevel
{
get
{
return EventHorizonBlazorInterop.Get<decimal>(
"ExampleClass",
"NoneLogLevel"
);
}
}
#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 readonly NoneLogLevel: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ ASTParserType parserType
[InlineData("PropertyJavaScriptTypes.ts", "Properties", "Scenarios", "PropertyJavaScriptTypes.Expected.txt", ASTParserType.Sdcb)]
[InlineData("PropertyParenthesized.ts", "Properties", "Scenarios", "PropertyParenthesized.Expected.txt", ASTParserType.Sdcb)]
[InlineData("PropertyStaticRootNamespace.ts", "Properties", "Scenarios", "PropertyStaticRootNamespace.Expected.txt", ASTParserType.Sdcb)]
[InlineData("StaticNoNamespace.d.ts", "Properties", "Scenarios", "StaticNoNamespace.d.Expected.txt", ASTParserType.Sdcb)]
[InlineData("TypeofResponse.ts", "Properties", "Scenarios", "TypeofResponse.Expected.txt", ASTParserType.Sdcb)]
[InlineData("TypeofToPrimitiveResponse.ts", "Properties", "Scenarios", "TypeofToPrimitiveResponse.Expected.txt", ASTParserType.Sdcb)]
[InlineData("UnionLiteralPropertyType.ts", "Properties", "Scenarios", "UnionLiteralPropertyType.Expected.txt", ASTParserType.Sdcb)]
Expand Down Expand Up @@ -120,6 +121,7 @@ ASTParserType parserType
[InlineData("PropertyJavaScriptTypes.ts", "Properties", "Scenarios", "PropertyJavaScriptTypes.Expected.txt", ASTParserType.NodeJS)]
[InlineData("PropertyParenthesized.ts", "Properties", "Scenarios", "PropertyParenthesized.Expected.txt", ASTParserType.NodeJS)]
[InlineData("PropertyStaticRootNamespace.ts", "Properties", "Scenarios", "PropertyStaticRootNamespace.Expected.txt", ASTParserType.NodeJS)]
[InlineData("StaticNoNamespace.d.ts", "Properties", "Scenarios", "StaticNoNamespace.d.Expected.txt", ASTParserType.NodeJS)]
[InlineData("TypeofResponse.ts", "Properties", "Scenarios", "TypeofResponse.Expected.txt", ASTParserType.NodeJS)]
[InlineData("TypeofToPrimitiveResponse.ts", "Properties", "Scenarios", "TypeofToPrimitiveResponse.Expected.txt", ASTParserType.NodeJS)]
[InlineData("UnionLiteralPropertyType.ts", "Properties", "Scenarios", "UnionLiteralPropertyType.Expected.txt", ASTParserType.NodeJS)]
Expand Down
Loading

0 comments on commit b95482a

Please sign in to comment.