Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW-FEATURE] Add attributes to Plain objects and add added properties as attribute in the poco type declarations #340

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,13 @@ public void CreateClassDeclaration(IClassDeclarationSyntax classDeclarationSynta
{
TypeCommAccessibility = eCommAccessibility.ReadOnly;
}

classDeclarationSyntax.UsingDirectives.ToList().ForEach(p => p.Visit(visitor, this));

var classDeclarations = this.Compilation.GetSemanticTree().Classes
.Where(p => p.FullyQualifiedName == classDeclaration.GetQualifiedName());
AddToSource(classDeclaration.Pragmas.AddedPropertiesAsAttributes());

AddToSource($"{classDeclaration.AccessModifier.Transform()}partial class {classDeclaration.Name}");

var isExtended = Compilation.GetSemanticTree().Types
Expand Down Expand Up @@ -109,6 +114,8 @@ public void CreateFieldDeclaration(IFieldDeclaration fieldDeclaration, IxNodeVis
{
if (fieldDeclaration.IsMemberEligibleForTranspile(this))
{
AddToSource(fieldDeclaration.Pragmas.AddAttributes());
AddToSource(fieldDeclaration.Pragmas.AddedPropertiesAsAttributes());
switch (fieldDeclaration.Type)
{
case IArrayTypeDeclaration arrayType:
Expand Down Expand Up @@ -182,6 +189,7 @@ public void CreateFile(IFileSyntax fileSyntax, IxNodeVisitor visitor)
{
AddToSource("using System;");
AddToSource("using AXSharp.Abstractions.Presentation;");
AddToSource("using AXSharp.Connector;");

foreach (var fileSyntaxUsingDirective in
fileSyntax.UsingDirectives
Expand Down Expand Up @@ -259,6 +267,8 @@ public void CreateVariableDeclaration(IVariableDeclaration fieldDeclaration, IxN
{
if (fieldDeclaration.IsMemberEligibleForTranspile(this))
{
AddToSource(fieldDeclaration.Pragmas.AddAttributes());
AddToSource(fieldDeclaration.Pragmas.AddedPropertiesAsAttributes());
switch (fieldDeclaration.Type)
{
case IArrayTypeDeclaration arrayType:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using AX.ST.Semantic.Pragmas;
using AXSharp.Compiler.Core;
using AXSharp.Compiler.Cs.Pragmas.PragmaParser;
using AXSharp.Connector;

namespace AXSharp.Compiler.Cs;

Expand Down Expand Up @@ -40,6 +41,29 @@ public static string AddAttributes(this IEnumerable<IPragma> pragmas)
.Select(p => Pragmas.PragmaParser.PragmaCompiler.Compile(p).Product));
}

public static string AddedPropertiesAsAttributes(this IEnumerable<IPragma> pragmas)
{
var properties = pragmas.Where(p =>
p.Content.StartsWith(PRAGMA_PROPERTY_SET_SIGNATURE))
.Select(p => Pragmas.PragmaParser.PragmaCompiler.Compile(p).Property);


var valueTuples = properties as (string PropertyName, string InitValue)[] ?? properties.ToArray();
if (valueTuples.Count() > 0)
{
var sb = new StringBuilder();

foreach (var property in valueTuples)
{
sb.AppendLine($"[AXSharp.Connector.AddedPropertiesAttribute(\"{property.PropertyName}\", {property.InitValue})]\n");
}

return sb.ToString();
}

return string.Empty;
}

/// <summary>
/// Produces property from list of ix pragmas declared on type declaration.
/// </summary>
Expand Down Expand Up @@ -74,7 +98,7 @@ public static string SetProperties(this IFieldDeclaration fieldDeclaration)
return string.Join("\r\n",
fieldDeclaration.Pragmas.Where(p => p.Content.StartsWith(PRAGMA_PROPERTY_SET_SIGNATURE)).Select(p => Pragmas.PragmaParser.PragmaCompiler.Compile(p, fieldDeclaration).Product));
}

public static VisitorProduct GetGenericAttributes(this ITypeDeclaration typeDeclaration)
{
return typeDeclaration.Pragmas
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ public override void AcceptVisitor(IAstVisitor visitor)
{

if (visitor is PragmaVisitor v)
{
v.Product.Product = MemberName != null
? $"{MemberName}.{PropertyName} = {InitValue};"
: $"{PropertyName} = {InitValue};";

if (PropertyName != null) v.Product.Property = (PropertyName, InitValue);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ public class VisitorProduct
public string? GenericConstrains { get; set; }
public IEnumerable<string> GenericTypes { get; set; }
public (string type, bool isPoco) GenericTypeAssignment { get; set; }

public (string PropertyName, string? InitValue) Property { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AXSharp.Abstractions.Presentation;
using AXSharp.Connector;

namespace Pocos
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AXSharp.Abstractions.Presentation;
using AXSharp.Connector;

namespace Pocos
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AXSharp.Abstractions.Presentation;
using AXSharp.Connector;

namespace Pocos
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AXSharp.Abstractions.Presentation;
using AXSharp.Connector;

namespace Pocos
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AXSharp.Abstractions.Presentation;
using AXSharp.Connector;

namespace Pocos
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AXSharp.Abstractions.Presentation;
using AXSharp.Connector;

namespace Pocos
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AXSharp.Abstractions.Presentation;
using AXSharp.Connector;

namespace Pocos
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AXSharp.Abstractions.Presentation;
using AXSharp.Connector;

namespace Pocos
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AXSharp.Abstractions.Presentation;
using AXSharp.Connector;

namespace Pocos
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AXSharp.Abstractions.Presentation;
using AXSharp.Connector;

namespace Pocos
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AXSharp.Abstractions.Presentation;
using AXSharp.Connector;

namespace Pocos
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AXSharp.Abstractions.Presentation;
using AXSharp.Connector;

namespace Pocos
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AXSharp.Abstractions.Presentation;
using AXSharp.Connector;

namespace Pocos
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AXSharp.Abstractions.Presentation;
using AXSharp.Connector;

namespace Pocos
{
Expand All @@ -11,6 +12,7 @@ public ClassWithPragmas()
{
}

[Container(Layout.Wrap)]
public ClassWithPragmasNamespace.ComplexType1 myComplexType { get; set; } = new ClassWithPragmasNamespace.ComplexType1();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AXSharp.Abstractions.Presentation;
using AXSharp.Connector;

namespace Pocos
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AXSharp.Abstractions.Presentation;
using AXSharp.Connector;

namespace Pocos
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AXSharp.Abstractions.Presentation;
using AXSharp.Connector;

namespace Pocos
{
Expand All @@ -11,6 +12,7 @@ public ClassWithArrays()
{
}

[CompilerOmitsAttribute("Onliner")]
public CompilerOmmits.Complex _must_be_omitted_in_onliner { get; set; } = new CompilerOmmits.Complex();
public Byte[] _primitive { get; set; } = new Byte[11];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AXSharp.Abstractions.Presentation;
using AXSharp.Connector;

namespace Pocos
{
Expand Down Expand Up @@ -50,14 +51,19 @@ public partial class unitsTwinController

public string mySTRING { get; set; } = string.Empty;
public string myWSTRING { get; set; } = string.Empty;
[ReadOnce()]
public string myWSTRING_readOnce { get; set; } = string.Empty;
[ReadOnly()]
public string myWSTRING_readOnly { get; set; } = string.Empty;
[ReadOnce()]
public ComplexForConfig cReadOnce { get; set; } = new ComplexForConfig();
[ReadOnly()]
public ComplexForConfig cReadOnly { get; set; } = new ComplexForConfig();
public global::Colorss Colorss { get; set; }

public UInt64 Colorsss { get; set; }

[CompilerOmitsAttribute("Onliner")]
public Boolean _must_be_omitted_in_onliner { get; set; }
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AXSharp.Abstractions.Presentation;
using AXSharp.Connector;

namespace Pocos
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AXSharp.Abstractions.Presentation;
using AXSharp.Connector;

namespace Pocos
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AXSharp.Abstractions.Presentation;
using AXSharp.Connector;
using Pocos.FileWithUsingsSimpleFirstLevelNamespace;
using Pocos.FileWithUsingsSimpleQualifiedNamespace.Qualified;
using Pocos.FileWithUsingsHelloLevelOne.FileWithUsingsHelloLevelTwo;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AXSharp.Abstractions.Presentation;
using AXSharp.Connector;

namespace Pocos
{
Expand Down Expand Up @@ -29,6 +30,9 @@ public Extendee2() : base()
{
}

[AXOpen.Data.AxoDataEntityAttribute]
[Container(Layout.Stack)]
[AXSharp.Connector.AddedPropertiesAttribute("AttributeName", "Shared Header")]
public GenericsTests.SomeTypeToBeGeneric SomeData { get; set; } = new GenericsTests.SomeTypeToBeGeneric();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AXSharp.Abstractions.Presentation;
using AXSharp.Connector;

namespace Pocos
{
Expand All @@ -11,8 +12,10 @@ public MembersWithMakeReadOnce()
{
}

[ReadOnce()]
public string makeReadOnceMember { get; set; } = string.Empty;
public string someOtherMember { get; set; } = string.Empty;
[ReadOnce()]
public makereadonce.ComplexMember makeReadComplexMember { get; set; } = new makereadonce.ComplexMember();
public makereadonce.ComplexMember someotherComplexMember { get; set; } = new makereadonce.ComplexMember();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AXSharp.Abstractions.Presentation;
using AXSharp.Connector;

namespace Pocos
{
Expand All @@ -11,8 +12,10 @@ public MembersWithMakeReadOnly()
{
}

[ReadOnly()]
public string makeReadOnceMember { get; set; } = string.Empty;
public string someOtherMember { get; set; } = string.Empty;
[ReadOnly()]
public makereadonly.ComplexMember makeReadComplexMember { get; set; } = new makereadonly.ComplexMember();
public makereadonly.ComplexMember someotherComplexMember { get; set; } = new makereadonly.ComplexMember();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AXSharp.Abstractions.Presentation;
using AXSharp.Connector;

namespace Pocos
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AXSharp.Abstractions.Presentation;
using AXSharp.Connector;

namespace Pocos
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AXSharp.Abstractions.Presentation;
using AXSharp.Connector;

namespace Pocos
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AXSharp.Abstractions.Presentation;
using AXSharp.Connector;

namespace Pocos
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AXSharp.Abstractions.Presentation;
using AXSharp.Connector;

namespace Pocos
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AXSharp.Abstractions.Presentation;
using AXSharp.Connector;

namespace Pocos
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AXSharp.Abstractions.Presentation;
using AXSharp.Connector;

namespace Pocos
{
Expand Down
Loading