Skip to content

Commit

Permalink
Merge pull request #328 from klee-contrib/from-mapper-property-param
Browse files Browse the repository at this point in the history
Propriétés comme paramètres de mapper `from`
  • Loading branch information
JabX authored Nov 28, 2023
2 parents d8fcf5c + 07c4fda commit 318770c
Show file tree
Hide file tree
Showing 47 changed files with 638 additions and 216 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
6 changes: 4 additions & 2 deletions TopModel.Core/FileModel/ModelFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ public class ModelFile
.Concat(Classes.SelectMany(c => new[] { c.DefaultPropertyReference, c.OrderPropertyReference, c.FlagPropertyReference }.Select(r => (r, (object)c.ExtendedProperties.FirstOrDefault(p => p.Name == r?.ReferenceName)))))
.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.Params).Concat(c.ToMappers)).Select(p => (p.ClassReference as Reference, (object)p.Class)))
.Concat(Classes.SelectMany(c => c.FromMappers.SelectMany(m => m.Params).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 == "this" || mr.Value.ReferenceName == "false" ? new Keyword { ModelFile = c.ModelFile } : m.Mappings.Values.FirstOrDefault(k => k.Name == mr.Value.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))))
.Concat(DataFlows.Select(d => (d.ClassReference as Reference, d.Class as object)))
Expand All @@ -80,6 +81,7 @@ public class ModelFile
.ToList();

public IList<IProperty> Properties => Classes.SelectMany(c => c.Properties)
.Concat(Classes.SelectMany(c => c.FromMapperProperties))
.Concat(Endpoints.SelectMany(e => e.Params))
.Concat(Endpoints.Select(e => e.Returns))
.Concat(Decorators.SelectMany(e => e.Properties))
Expand Down
89 changes: 58 additions & 31 deletions TopModel.Core/Loaders/ClassLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,7 @@ public Class Load(Parser parser)
case "properties":
parser.ConsumeSequence(() =>
{
foreach (var property in _propertyLoader.Load(parser))
{
classe.Properties.Add(property);
}
classe.Properties.Add(_propertyLoader.Load(parser));
});
break;
case "unique":
Expand Down Expand Up @@ -138,7 +135,7 @@ public Class Load(Parser parser)
case "from":
parser.ConsumeSequence(() =>
{
var mapper = new FromMapper();
var mapper = new FromMapper { Class = classe };
classe.FromMappers.Add(mapper);

parser.ConsumeMapping(prop =>
Expand All @@ -152,37 +149,67 @@ public Class Load(Parser parser)
mapper.Reference = new LocatedString(prop);
parser.ConsumeSequence(() =>
{
var param = new ClassMappings();
mapper.Params.Add(param);
parser.Consume<MappingStart>();
if (parser.Current is Scalar { Value: "class" })
{
var param = new ClassMappings();
mapper.Params.Add(param);

Scalar classScalar = null!;
parser.ConsumeMapping(prop =>
Scalar classScalar = null!;
while (parser.Current is not MappingEnd)
{
var prop = parser.Consume<Scalar>();
switch (prop.Value)
{
case "class":
classScalar = parser.Consume<Scalar>();
param.ClassReference = new ClassReference(classScalar);
break;
case "required":
param.Required = parser.Consume<Scalar>().Value == "true";
break;
case "comment":
param.Comment = parser.Consume<Scalar>().Value;
break;
case "name":
param.Name = new LocatedString(parser.Consume<Scalar>());
break;
case "mappings":
parser.ConsumeMapping(prop =>
{
param.MappingReferences.Add(new Reference(prop), new Reference(parser.Consume<Scalar>()));
});
break;
}
}

param.Name ??= new LocatedString(classScalar) { Value = param.ClassReference.ReferenceName.ToCamelCase(strictIfUppercase: true) };
}
else if (parser.Current is Scalar { Value: "property" })
{
switch (prop.Value)
var param = new PropertyMapping { FromMapper = mapper };
mapper.Params.Add(param);
while (parser.Current is not MappingEnd)
{
case "class":
classScalar = parser.Consume<Scalar>();
param.ClassReference = new ClassReference(classScalar);
break;
case "required":
param.Required = parser.Consume<Scalar>().Value == "true";
break;
case "comment":
param.Comment = parser.Consume<Scalar>().Value;
break;
case "name":
param.Name = new LocatedString(parser.Consume<Scalar>());
break;
case "mappings":
parser.ConsumeMapping(prop =>
{
param.MappingReferences.Add(new Reference(prop), new Reference(parser.Consume<Scalar>()));
});
break;
var prop = parser.Consume<Scalar>();
switch (prop.Value)
{
case "property":
param.Property = _propertyLoader.Load(parser);
param.Property.PropertyMapping = param;
break;
case "target":
param.TargetPropertyReference = new Reference(parser.Consume<Scalar>());
break;
}
}
});
}
else
{
throw new ModelException(classe, $"Erreur dans la construction des paramètres du mapper 'from'.");
}

param.Name ??= new LocatedString(classScalar) { Value = param.ClassReference.ReferenceName.ToCamelCase(strictIfUppercase: true) };
parser.Consume<MappingEnd>();
});
break;
}
Expand Down
5 changes: 1 addition & 4 deletions TopModel.Core/Loaders/DecoratorLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ public Decorator Load(Parser parser)
case "properties":
parser.ConsumeSequence(() =>
{
foreach (var property in _propertyLoader.Load(parser))
{
decorator.Properties.Add(property);
}
decorator.Properties.Add(_propertyLoader.Load(parser));
});
break;
default:
Expand Down
11 changes: 4 additions & 7 deletions TopModel.Core/Loaders/EndpointLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,14 @@ public Endpoint Load(Parser parser)
case "params":
parser.ConsumeSequence(() =>
{
foreach (var property in _propertyLoader.Load(parser))
{
property.Endpoint = endpoint;
endpoint.Params.Add(property);
}
var property = _propertyLoader.Load(parser);
property.Endpoint = endpoint;
endpoint.Params.Add(property);
});
break;
case "returns":
endpoint.Returns = _propertyLoader.Load(parser).First();
endpoint.Returns = _propertyLoader.Load(parser);
endpoint.Returns.Endpoint = endpoint;
parser.Consume<MappingEnd>();
break;
case "decorators":
parser.ConsumeSequence(() =>
Expand Down
Loading

0 comments on commit 318770c

Please sign in to comment.