Skip to content

Commit

Permalink
[JPA] Donner la possibilité de masque l'annotation @generated
Browse files Browse the repository at this point in the history
  • Loading branch information
gideruette committed Jun 25, 2024
1 parent e8fd3bc commit 78cd90a
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 16 deletions.
5 changes: 5 additions & 0 deletions TopModel.Generator.Jpa/JpaConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public class JpaConfig : GeneratorConfigBase
/// </summary>
public bool AssociationRemovers { get; set; } = false;

/// <summary>
/// Option pour générer l'annotation @Generated("TopModel : https://github.com/klee-contrib/topmodel")
/// </summary>
public bool GeneratedHint { get; set; } = true;

/// <summary>
/// Option pour générer une enum des champs des classes persistées
/// </summary>
Expand Down
8 changes: 6 additions & 2 deletions TopModel.Generator.Jpa/JpaMapperGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ protected override void HandleFile(string fileName, string tag, IList<(Class Cla
}

var javaOrJakarta = Config.PersistenceMode.ToString().ToLower();
fw.AddImport($"{javaOrJakarta}.annotation.Generated");
fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")");
if (Config.GeneratedHint)
{
fw.AddImport($"{javaOrJakarta}.annotation.Generated");
fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")");
}

fw.WriteLine($@"public class {Config.GetMapperName(mapperNs, modelPath)} {{");

fw.WriteLine();
Expand Down
7 changes: 5 additions & 2 deletions TopModel.Generator.Jpa/JpaModelGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,11 @@ private void WriteAnnotations(JavaWriter fw, Class classe, string tag)
fw.WriteDocStart(0, classe.Comment);
fw.WriteDocEnd(0);
var javaOrJakarta = Config.PersistenceMode.ToString().ToLower();
fw.AddImport($"{javaOrJakarta}.annotation.Generated");
fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")");
if (Config.GeneratedHint)
{
fw.AddImport($"{javaOrJakarta}.annotation.Generated");
fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")");
}

if (classe.IsPersistent)
{
Expand Down
8 changes: 6 additions & 2 deletions TopModel.Generator.Jpa/JpaModelInterfaceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ protected override void HandleClass(string fileName, Class classe, string tag)
var extends = Config.GetClassExtends(classe);
var implements = Config.GetClassImplements(classe);

fw.AddImport($"{javaOrJakarta}.annotation.Generated");
fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")");
if (Config.GeneratedHint)
{
fw.AddImport($"{javaOrJakarta}.annotation.Generated");
fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")");
}

fw.WriteLine($"public interface {classe.NamePascal} {{");

WriteGetters(fw, classe, tag);
Expand Down
8 changes: 6 additions & 2 deletions TopModel.Generator.Jpa/SpringClientApiGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ protected override void HandleFile(string filePath, string fileName, string tag,
}

var javaOrJakarta = Config.PersistenceMode.ToString().ToLower();
fw.AddImport($"{javaOrJakarta}.annotation.Generated");
fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")");
if (Config.GeneratedHint)
{
fw.AddImport($"{javaOrJakarta}.annotation.Generated");
fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")");
}

fw.WriteLine($"public interface {className} {{");

fw.WriteLine();
Expand Down
16 changes: 12 additions & 4 deletions TopModel.Generator.Jpa/SpringDataFlowGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,12 @@ private void WriteClassFlow(string fileName, DataFlow dataFlow, string tag)
fw.WriteLine();
fw.WriteLine("@Configuration");
var javaOrJakarta = Config.PersistenceMode.ToString().ToLower();
fw.AddImport($"{javaOrJakarta}.annotation.Generated");
fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")");
if (Config.GeneratedHint)
{
fw.AddImport($"{javaOrJakarta}.annotation.Generated");
fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")");
}

fw.WriteClassDeclaration($"{dataFlow.Name}Flow", null);
fw.WriteLine();
fw.WriteLine(1, $@"protected {dataFlow.Name}Flow() {{");
Expand Down Expand Up @@ -349,8 +353,12 @@ private void WriteModuleConfig(string module, IEnumerable<DataFlow> flows)
fw.WriteLine();
fw.WriteLine("@Configuration");
var javaOrJakarta = Config.PersistenceMode.ToString().ToLower();
fw.AddImport($"{javaOrJakarta}.annotation.Generated");
fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")");
if (Config.GeneratedHint)
{
fw.AddImport($"{javaOrJakarta}.annotation.Generated");
fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")");
}

fw.WriteLine(@$"@Import({{{string.Join(", ", flows.Select(f => $@"{f.Name.ToPascalCase()}Flow.class"))}}})");

var className = configFilePath.Split("\\").Last().Split('.').First();
Expand Down
8 changes: 6 additions & 2 deletions TopModel.Generator.Jpa/SpringRestTemplateApiGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ protected override void HandleFile(string filePath, string fileName, string tag,
fw.WriteLine();

var javaOrJakarta = Config.PersistenceMode.ToString().ToLower();
fw.AddImport($"{javaOrJakarta}.annotation.Generated");
fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")");
if (Config.GeneratedHint)
{
fw.AddImport($"{javaOrJakarta}.annotation.Generated");
fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")");
}

fw.WriteLine($"public abstract class {className} {{");

fw.WriteLine();
Expand Down
8 changes: 6 additions & 2 deletions TopModel.Generator.Jpa/SpringServerApiGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ protected override void HandleFile(string filePath, string fileName, string tag,
}

var javaOrJakarta = Config.PersistenceMode.ToString().ToLower();
fw.AddImport($"{javaOrJakarta}.annotation.Generated");
fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")");
if (Config.GeneratedHint)
{
fw.AddImport($"{javaOrJakarta}.annotation.Generated");
fw.WriteLine("@Generated(\"TopModel : https://github.com/klee-contrib/topmodel\")");
}

fw.WriteLine($"public interface {className} {{");

fw.WriteLine();
Expand Down
5 changes: 5 additions & 0 deletions TopModel.Generator.Jpa/jpa.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@
"description": "Option pour générer des méthodes de suppression pour les associations oneToMany et manyToMany. Ces méthodes permettent de synchroniser les objets supprimés",
"default": "false"
},
"generatedHint": {
"type": "boolean",
"description": "Option pour générer l'annotation @Generated('TopModel : https://github.com/klee-contrib/topmodel')",
"default": "true"
},
"fieldsEnum": {
"type": "string",
"description": "Option pour générer une enum des champs des classes persistées",
Expand Down
6 changes: 6 additions & 0 deletions docs/generator/jpa.md
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,12 @@ Le générateur créé un fichier de configuration de job par module. Ce job ord

_Valeur par défaut_: `false`

- `generatedHint`

Option pour générer l'annotation @Generated("TopModel : https://github.com/klee-contrib/topmodel")

_Valeur par défaut_: `true`

- `persistenceMode`

Mode de génération de la persistence (`"javax"` ou `"jakarta"`).
Expand Down

0 comments on commit 78cd90a

Please sign in to comment.