Skip to content

Commit

Permalink
[PropertyMapping] Résolution TargetProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
JabX committed Nov 26, 2023
1 parent 3b79b05 commit d7dd0d1
Show file tree
Hide file tree
Showing 22 changed files with 250 additions and 22 deletions.
117 changes: 117 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,120 @@ dotnet_diagnostic.SA1642.severity = none
dotnet_diagnostic.SA1643.severity = none
dotnet_diagnostic.SX1309.severity = warning
dotnet_diagnostic.CA2254.severity = none

[*.cs]
#### Styles de nommage ####

# Règles de nommage

dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i

dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case

dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case

# Spécifications de symboles

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.required_modifiers =

dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =

# Styles de nommage

dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_accessors = true:silent
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = false:silent
csharp_style_prefer_switch_expression = true:suggestion
csharp_style_prefer_pattern_matching = true:silent
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_prefer_not_pattern = true:suggestion
csharp_style_prefer_extended_property_pattern = true:suggestion
csharp_prefer_simple_using_statement = true:suggestion
csharp_prefer_braces = true:silent
dotnet_diagnostic.SA1010.severity = none

[*.vb]
#### Styles de nommage ####

# Règles de nommage

dotnet_naming_rule.interface_should_be_commence_par_i.severity = suggestion
dotnet_naming_rule.interface_should_be_commence_par_i.symbols = interface
dotnet_naming_rule.interface_should_be_commence_par_i.style = commence_par_i

dotnet_naming_rule.types_should_be_casse_pascal.severity = suggestion
dotnet_naming_rule.types_should_be_casse_pascal.symbols = types
dotnet_naming_rule.types_should_be_casse_pascal.style = casse_pascal

dotnet_naming_rule.membres_autres_que_des_champs_should_be_casse_pascal.severity = suggestion
dotnet_naming_rule.membres_autres_que_des_champs_should_be_casse_pascal.symbols = membres_autres_que_des_champs
dotnet_naming_rule.membres_autres_que_des_champs_should_be_casse_pascal.style = casse_pascal

# Spécifications de symboles

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected
dotnet_naming_symbols.types.required_modifiers =

dotnet_naming_symbols.membres_autres_que_des_champs.applicable_kinds = property, event, method
dotnet_naming_symbols.membres_autres_que_des_champs.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected
dotnet_naming_symbols.membres_autres_que_des_champs.required_modifiers =

# Styles de nommage

dotnet_naming_style.commence_par_i.required_prefix = I
dotnet_naming_style.commence_par_i.required_suffix =
dotnet_naming_style.commence_par_i.word_separator =
dotnet_naming_style.commence_par_i.capitalization = pascal_case

dotnet_naming_style.casse_pascal.required_prefix =
dotnet_naming_style.casse_pascal.required_suffix =
dotnet_naming_style.casse_pascal.word_separator =
dotnet_naming_style.casse_pascal.capitalization = pascal_case

dotnet_naming_style.casse_pascal.required_prefix =
dotnet_naming_style.casse_pascal.required_suffix =
dotnet_naming_style.casse_pascal.word_separator =
dotnet_naming_style.casse_pascal.capitalization = pascal_case

[*.{cs,vb}]
tab_width = 4
indent_size = 4
1 change: 1 addition & 0 deletions TopModel.Core/FileModel/ModelFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class ModelFile
.Concat(Classes.SelectMany(c => c.UniqueKeyReferences.SelectMany(uk => uk).Select(propRef => (propRef, (object)c.Properties.FirstOrDefault(p => p.Name == propRef.ReferenceName)))))
.Concat(Classes.SelectMany(c => c.ValueReferences.SelectMany(rv => rv.Value).Select(prop => (prop.Key, (object)c.ExtendedProperties.FirstOrDefault(p => p.Name == prop.Key.ReferenceName)))))
.Concat(Classes.SelectMany(c => c.FromMappers.SelectMany(m => m.ClassParams).Concat(c.ToMappers)).Select(p => (p.ClassReference as Reference, (object)p.Class)))
.Concat(Classes.SelectMany(c => c.FromMappers.SelectMany(m => m.PropertyParams)).Select(p => (p.TargetPropertyReference as Reference, (object)p.TargetProperty)))
.Concat(Classes.SelectMany(c => c.FromMappers.SelectMany(m => m.ClassParams).Concat(c.ToMappers).SelectMany(m => m.MappingReferences.SelectMany(mr => new[] { (mr.Key, (object)c.ExtendedProperties.FirstOrDefault(k => k.Name == mr.Key.ReferenceName)), (mr.Value, mr.Value.ReferenceName == "false" ? new Keyword { ModelFile = c.ModelFile } : m.Mappings.Values.FirstOrDefault(k => k.Name == mr.Value.ReferenceName)) }))))
.Concat(Converters.SelectMany(c => c.DomainsFromReferences.Select(d => (d as Reference, c.From.FirstOrDefault(dom => dom.Name == d.ReferenceName) as object))))
.Concat(Converters.SelectMany(c => c.DomainsToReferences.Select(d => (d as Reference, c.To.FirstOrDefault(dom => dom.Name == d.ReferenceName) as object))))
Expand Down
15 changes: 5 additions & 10 deletions TopModel.Core/Loaders/ClassLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,24 +187,19 @@ public Class Load(Parser parser)
}
else if (parser.Current is Scalar { Value: "property" })
{
var param = new PropertyMapping { FromMapper = mapper };
mapper.Params.Add(param);
while (parser.Current is not MappingEnd)
{
var prop = parser.Consume<Scalar>();
switch (prop.Value)
{
case "property":
var p = _propertyLoader.Load(parser);
var param = new PropertyMapping { Property = p, FromMapper = mapper };
p.PropertyMapping = param;
mapper.Params.Add(param);
param.Property = _propertyLoader.Load(parser);
param.Property.PropertyMapping = param;
break;
case "target":
var targetReference = new Reference(parser.Consume<Scalar>());
foreach (var cp in mapper.PropertyParams)
{
cp.TargetPropertyReference = targetReference;
}

param.TargetPropertyReference = new Reference(parser.Consume<Scalar>());
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion TopModel.Core/Model/ClassMappings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ClassMappings
#nullable enable
public string? Comment { get; set; }

public Dictionary<IProperty, IFieldProperty> Mappings { get; } = new();
public Dictionary<IProperty, IProperty> Mappings { get; } = new();

public Dictionary<Reference, Reference> MappingReferences { get; } = new();
}
11 changes: 11 additions & 0 deletions TopModel.Core/Model/MappingExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using OneOf;

namespace TopModel.Core;

public static class MappingExtensions
{
public static string GetName(this OneOf<ClassMappings, PropertyMapping> mapping)
{
return mapping.Match(c => c.Name.ToString(), p => p.Property.Name);
}
}
10 changes: 10 additions & 0 deletions TopModel.Core/ModelErrorType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@ public enum ModelErrorType
/// </summary>
TMD1031,

/// <summary>
/// La propriété '{mapping.Property.Name}' doit être une composition de la même classe que '{mapping.TargetProperty.Name}' pour définir un mapping entre les deux.
/// </summary>
TMD1032,

/// <summary>
/// La propriété '{mapping.Property.Name}' ne peut pas être une composition pour définir un mapping vers '{mapping.TargetProperty.Name}'.
/// </summary>
TMD1033,

/// <summary>
/// Le flux de données est introuvable dans le fichier ou l'une de ses références.
/// </summary>
Expand Down
16 changes: 15 additions & 1 deletion TopModel.Core/ModelExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using TopModel.Core.FileModel;
using OneOf;
using TopModel.Core.FileModel;

namespace TopModel.Core;

Expand Down Expand Up @@ -118,6 +119,8 @@ public static ModelFile GetFile(this object? objet)
DataFlow d => d.Location,
FromMapper m => m.Reference.Location,
ClassMappings c => c.Name.Location,
PropertyMapping p => p.Property.GetLocation(),
OneOf<ClassMappings, PropertyMapping> p => p.Match(c => c.GetLocation(), p => p.GetLocation()),
Converter c => c.Location,
_ => null
};
Expand All @@ -140,6 +143,17 @@ public static ModelFile GetFile(this object? objet)
}
}

if (property.Class != null)
{
foreach (var mapping in property.Class.FromMappers.SelectMany(fm => fm.PropertyParams))
{
if (mapping.TargetPropertyReference != null && mapping.TargetProperty == property)
{
yield return (mapping.TargetPropertyReference, mapping.TargetProperty.GetFile());
}
}
}

if (property is IFieldProperty fp)
{
foreach (var alp in modelStore.Files.SelectMany(c => c.Properties).OfType<AliasProperty>())
Expand Down
Loading

0 comments on commit d7dd0d1

Please sign in to comment.