From f0286bccbffdc4198c09580f6ef70b1fd3deb7a0 Mon Sep 17 00:00:00 2001 From: LarsReinken Date: Tue, 1 Mar 2022 12:09:28 +0100 Subject: [PATCH 1/4] #430 use annotations of the patchfile, if javamerge_override is set. --- .../cobigen/javaplugin/merger/JavaMerger.java | 13 +++++++ .../unittest/merger/JavaMergerTest.java | 39 +++++++++++++++++++ .../merger/BaseFile_ClassAnnotation.java | 13 +++++++ .../merger/BaseFile_PropertyAnnotation.java | 18 +++++++++ .../merger/PatchFile_ClassAnnotation.java | 16 ++++++++ .../merger/PatchFile_PropertyAnnotation.java | 22 +++++++++++ 6 files changed, 121 insertions(+) create mode 100644 cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/BaseFile_ClassAnnotation.java create mode 100644 cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/BaseFile_PropertyAnnotation.java create mode 100644 cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/PatchFile_ClassAnnotation.java create mode 100644 cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/PatchFile_PropertyAnnotation.java diff --git a/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/main/java/com/devonfw/cobigen/javaplugin/merger/JavaMerger.java b/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/main/java/com/devonfw/cobigen/javaplugin/merger/JavaMerger.java index 6aaeb9d70f..0f3fb91973 100644 --- a/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/main/java/com/devonfw/cobigen/javaplugin/merger/JavaMerger.java +++ b/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/main/java/com/devonfw/cobigen/javaplugin/merger/JavaMerger.java @@ -112,6 +112,7 @@ public String merge(File base, String patch, String targetCharset) throws MergeE */ private ModifyableJavaClass merge(ModifyableJavaClass baseClass, ModifyableJavaClass patchClass) { + mergeClassAnnotation(baseClass, patchClass); mergeImports(baseClass, patchClass); mergeFields(baseClass, patchClass); mergeInnerClasses(baseClass, patchClass); @@ -120,6 +121,18 @@ private ModifyableJavaClass merge(ModifyableJavaClass baseClass, ModifyableJavaC return baseClass; } + /** + * @param baseClass {@link JavaClass} + * @param patchClass {@link JavaClass} + */ + private void mergeClassAnnotation(ModifyableJavaClass baseClass, ModifyableJavaClass patchClass) { + + if (this.patchOverrides) { + baseClass.setAnnotations(patchClass.getAnnotations()); + } + + } + /** * Merges all super types of the two class sources * diff --git a/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/java/com/devonfw/cobigen/javaplugin/unittest/merger/JavaMergerTest.java b/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/java/com/devonfw/cobigen/javaplugin/unittest/merger/JavaMergerTest.java index cb9f176e35..9bb38d5715 100644 --- a/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/java/com/devonfw/cobigen/javaplugin/unittest/merger/JavaMergerTest.java +++ b/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/java/com/devonfw/cobigen/javaplugin/unittest/merger/JavaMergerTest.java @@ -517,4 +517,43 @@ private JavaSource getMergedSource(File baseFile, File patchFile, boolean overri return getFirstJavaClass(new StringReader(mergedContents)).getSource(); } + /** + * Tests merging the class annotation into the baseFile + * + * @throws IOException shouldn't happen + * @throws MergeException shouldn't happen either + */ + @Test + public void testMergeClassAnnotation() throws IOException, MergeException { + + File baseFile = new File(testFileRootPath + "BaseFile_ClassAnnotation.java"); + File patchFile = new File(testFileRootPath + "PatchFile_ClassAnnotation.java"); + + String mergedContents = new JavaMerger("", true).merge(baseFile, + FileUtils.readFileToString(patchFile, StandardCharsets.UTF_8), "UTF-8"); + + assertThat(mergedContents).contains("@Entity"); + assertThat(mergedContents).contains("@javax.persistence.Table(name=\"Visitor\")"); + + } + + /** + * Tests merging the property annotation into the baseFile + * + * @throws IOException shouldn't happen + * @throws MergeException shouldn't happen either + */ + @Test + public void testMergePropertyAnnotation() throws IOException, MergeException { + + File baseFile = new File(testFileRootPath + "BaseFile_PropertyAnnotation.java"); + File patchFile = new File(testFileRootPath + "PatchFile_PropertyAnnotation.java"); + + String mergedContents = new JavaMerger("", true).merge(baseFile, + FileUtils.readFileToString(patchFile, StandardCharsets.UTF_8), "UTF-8"); + + assertThat(mergedContents).contains("@Column(name= \"USERNAME\")"); + assertThat(mergedContents).contains("@Column(name=\"NAME\")"); + + } } diff --git a/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/BaseFile_ClassAnnotation.java b/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/BaseFile_ClassAnnotation.java new file mode 100644 index 0000000000..2c57b628b5 --- /dev/null +++ b/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/BaseFile_ClassAnnotation.java @@ -0,0 +1,13 @@ +package com.devonfw.application.jtqj.general.dataaccess.api; + +import com.devonfw.application.jtqj.general.common.api.Visitor; + +public class VisitorEntity extends ApplicationPersistenceEntity implements Visitor { + + private String username; + + private String name; + + private static final long serialVersionUID = 1L; + +} diff --git a/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/BaseFile_PropertyAnnotation.java b/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/BaseFile_PropertyAnnotation.java new file mode 100644 index 0000000000..c0d9831a65 --- /dev/null +++ b/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/BaseFile_PropertyAnnotation.java @@ -0,0 +1,18 @@ +package com.devonfw.application.jtqj.general.dataaccess.api; + +import com.devonfw.application.jtqj.general.common.api.Visitor; + +/** + * Data access object for Visitor entities + */ +@Entity +@javax.persistence.Table(name = "Visitor") +public class VisitorEntity extends ApplicationPersistenceEntity implements Visitor { + + private String username; + + private String name; + + private static final long serialVersionUID = 1L; + +} diff --git a/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/PatchFile_ClassAnnotation.java b/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/PatchFile_ClassAnnotation.java new file mode 100644 index 0000000000..640c7cc03c --- /dev/null +++ b/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/PatchFile_ClassAnnotation.java @@ -0,0 +1,16 @@ +package com.devonfw.application.jtqj.general.dataaccess.api; + +import javax.persistence.Entity; + +import com.devonfw.application.jtqj.general.common.api.Visitor; + +/** + * Data access object for Visitor entities + */ +@Entity +@javax.persistence.Table(name = "Visitor") +public class VisitorEntity extends ApplicationPersistenceEntity implements Visitor { + + private static final long serialVersionUID = 1L; + +} diff --git a/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/PatchFile_PropertyAnnotation.java b/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/PatchFile_PropertyAnnotation.java new file mode 100644 index 0000000000..2cea6f2b90 --- /dev/null +++ b/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/PatchFile_PropertyAnnotation.java @@ -0,0 +1,22 @@ +package com.devonfw.application.jtqj.general.dataaccess.api; + +import javax.persistence.Entity; + +import com.devonfw.application.jtqj.general.common.api.Visitor; + +/** + * Data access object for Visitor entities + */ +@Entity +@javax.persistence.Table(name = "Visitor") +public class VisitorEntity extends ApplicationPersistenceEntity implements Visitor { + + private static final long serialVersionUID = 1L; + + @Column(name = "USERNAME") + private String username; + + + @Column(name = "NAME") + private String name; +} From a8d1ff790058f04924a22688f104334a06d28b08 Mon Sep 17 00:00:00 2001 From: LarsReinken Date: Wed, 4 May 2022 08:58:21 +0200 Subject: [PATCH 2/4] implement merge method and use it to merge class annotation --- .../cobigen/javaplugin/merger/JavaMerger.java | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/main/java/com/devonfw/cobigen/javaplugin/merger/JavaMerger.java b/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/main/java/com/devonfw/cobigen/javaplugin/merger/JavaMerger.java index 0f3fb91973..7a7a4d748f 100644 --- a/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/main/java/com/devonfw/cobigen/javaplugin/merger/JavaMerger.java +++ b/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/main/java/com/devonfw/cobigen/javaplugin/merger/JavaMerger.java @@ -10,6 +10,9 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; import com.devonfw.cobigen.api.exception.MergeException; import com.devonfw.cobigen.api.extension.Merger; @@ -17,6 +20,7 @@ import com.devonfw.cobigen.api.util.SystemUtil; import com.devonfw.cobigen.javaplugin.inputreader.JavaParserUtil; import com.devonfw.cobigen.javaplugin.merger.libextension.ModifyableJavaClass; +import com.thoughtworks.qdox.model.JavaAnnotation; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaConstructor; import com.thoughtworks.qdox.model.JavaField; @@ -127,10 +131,24 @@ private ModifyableJavaClass merge(ModifyableJavaClass baseClass, ModifyableJavaC */ private void mergeClassAnnotation(ModifyableJavaClass baseClass, ModifyableJavaClass patchClass) { - if (this.patchOverrides) { - baseClass.setAnnotations(patchClass.getAnnotations()); - } + List baseAnnotations = this.patchOverrides ? patchClass.getAnnotations() + : baseClass.getAnnotations(); + List patchAnnotations = this.patchOverrides ? baseClass.getAnnotations() + : patchClass.getAnnotations(); + + baseClass.setAnnotations(mergeAnnotation(baseAnnotations, patchAnnotations)); + + } + + private List mergeAnnotation(List baseAnnotations, + List patchAnnotations) { + + Set annotationNames = baseAnnotations.stream().map(a -> a.getType().getName()).collect(Collectors.toSet()); + + List annotationsToMerge = patchAnnotations.stream() + .filter(a -> !annotationNames.contains(a.getType().getName())).collect(Collectors.toList()); + return Stream.of(baseAnnotations, annotationsToMerge).flatMap(a -> a.stream()).collect(Collectors.toList()); } /** From b8d21bb820c46733e333800391291f97173beb44 Mon Sep 17 00:00:00 2001 From: LarsReinken Date: Wed, 4 May 2022 13:24:20 +0200 Subject: [PATCH 3/4] merge implementation of fields and methods, and tests --- .../cobigen/javaplugin/merger/JavaMerger.java | 37 +++++++-------- .../unittest/merger/JavaMergerTest.java | 47 ++++++++++++++++++- .../merger/BaseFile_ClassAnnotation.java | 1 + .../merger/BaseFile_MethodAnnotation.java | 21 +++++++++ .../merger/BaseFile_PropertyAnnotation.java | 8 ++-- .../merger/PatchFile_MethodAnnotation.java | 22 +++++++++ 6 files changed, 112 insertions(+), 24 deletions(-) create mode 100644 cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/BaseFile_MethodAnnotation.java create mode 100644 cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/PatchFile_MethodAnnotation.java diff --git a/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/main/java/com/devonfw/cobigen/javaplugin/merger/JavaMerger.java b/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/main/java/com/devonfw/cobigen/javaplugin/merger/JavaMerger.java index 7a7a4d748f..e4b35ffb83 100644 --- a/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/main/java/com/devonfw/cobigen/javaplugin/merger/JavaMerger.java +++ b/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/main/java/com/devonfw/cobigen/javaplugin/merger/JavaMerger.java @@ -26,6 +26,8 @@ import com.thoughtworks.qdox.model.JavaField; import com.thoughtworks.qdox.model.JavaInitializer; import com.thoughtworks.qdox.model.JavaMethod; +import com.thoughtworks.qdox.model.impl.DefaultJavaField; +import com.thoughtworks.qdox.model.impl.DefaultJavaMethod; import com.thoughtworks.qdox.parser.ParseException; /** @@ -116,7 +118,7 @@ public String merge(File base, String patch, String targetCharset) throws MergeE */ private ModifyableJavaClass merge(ModifyableJavaClass baseClass, ModifyableJavaClass patchClass) { - mergeClassAnnotation(baseClass, patchClass); + baseClass.setAnnotations(mergeAnnotation(baseClass.getAnnotations(), patchClass.getAnnotations())); mergeImports(baseClass, patchClass); mergeFields(baseClass, patchClass); mergeInnerClasses(baseClass, patchClass); @@ -126,29 +128,21 @@ private ModifyableJavaClass merge(ModifyableJavaClass baseClass, ModifyableJavaC } /** - * @param baseClass {@link JavaClass} - * @param patchClass {@link JavaClass} + * @param baseAnnotations {@link JavaClass} + * @param patchAnnotations {@link JavaClass} */ - private void mergeClassAnnotation(ModifyableJavaClass baseClass, ModifyableJavaClass patchClass) { - - List baseAnnotations = this.patchOverrides ? patchClass.getAnnotations() - : baseClass.getAnnotations(); - List patchAnnotations = this.patchOverrides ? baseClass.getAnnotations() - : patchClass.getAnnotations(); - - baseClass.setAnnotations(mergeAnnotation(baseAnnotations, patchAnnotations)); - - } - private List mergeAnnotation(List baseAnnotations, List patchAnnotations) { - Set annotationNames = baseAnnotations.stream().map(a -> a.getType().getName()).collect(Collectors.toSet()); + List bAnnotations = this.patchOverrides ? patchAnnotations : baseAnnotations; + List pAnnotations = this.patchOverrides ? baseAnnotations : patchAnnotations; - List annotationsToMerge = patchAnnotations.stream() + Set annotationNames = bAnnotations.stream().map(a -> a.getType().getName()).collect(Collectors.toSet()); + + List annotationsToMerge = pAnnotations.stream() .filter(a -> !annotationNames.contains(a.getType().getName())).collect(Collectors.toList()); - return Stream.of(baseAnnotations, annotationsToMerge).flatMap(a -> a.stream()).collect(Collectors.toList()); + return Stream.of(bAnnotations, annotationsToMerge).flatMap(a -> a.stream()).collect(Collectors.toList()); } /** @@ -262,9 +256,11 @@ private void mergeFields(ModifyableJavaClass baseClass, ModifyableJavaClass patc if (baseField == null) { baseClass.addField(patchField); } else { + ((DefaultJavaField) baseField) + .setAnnotations(new ArrayList<>(mergeAnnotation(baseField.getAnnotations(), patchField.getAnnotations()))); if (this.patchOverrides) { baseClass.replace(baseField, patchField); - } // else do not override + } } } } @@ -319,11 +315,14 @@ private void mergeMethods(ModifyableJavaClass baseClass, ModifyableJavaClass pat if (baseMethod == null) { baseClass.addMethod(patchMethod); } else { + ((DefaultJavaMethod) baseMethod) + .setAnnotations(mergeAnnotation(baseMethod.getAnnotations(), patchMethod.getAnnotations())); if (this.patchOverrides) { baseClass.replace(baseMethod, patchMethod); - } // else do not override + } } } + } /** diff --git a/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/java/com/devonfw/cobigen/javaplugin/unittest/merger/JavaMergerTest.java b/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/java/com/devonfw/cobigen/javaplugin/unittest/merger/JavaMergerTest.java index 9bb38d5715..e7081800b8 100644 --- a/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/java/com/devonfw/cobigen/javaplugin/unittest/merger/JavaMergerTest.java +++ b/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/java/com/devonfw/cobigen/javaplugin/unittest/merger/JavaMergerTest.java @@ -529,16 +529,23 @@ public void testMergeClassAnnotation() throws IOException, MergeException { File baseFile = new File(testFileRootPath + "BaseFile_ClassAnnotation.java"); File patchFile = new File(testFileRootPath + "PatchFile_ClassAnnotation.java"); + // with override String mergedContents = new JavaMerger("", true).merge(baseFile, FileUtils.readFileToString(patchFile, StandardCharsets.UTF_8), "UTF-8"); assertThat(mergedContents).contains("@Entity"); assertThat(mergedContents).contains("@javax.persistence.Table(name=\"Visitor\")"); + // without override + mergedContents = new JavaMerger("", false).merge(baseFile, + FileUtils.readFileToString(patchFile, StandardCharsets.UTF_8), "UTF-8"); + + assertThat(mergedContents).contains("@Entity"); + assertThat(mergedContents).contains("@javax.persistence.Table(name=\"Visits\")"); } /** - * Tests merging the property annotation into the baseFile + * Tests merging a property annotation into the baseFile * * @throws IOException shouldn't happen * @throws MergeException shouldn't happen either @@ -549,11 +556,47 @@ public void testMergePropertyAnnotation() throws IOException, MergeException { File baseFile = new File(testFileRootPath + "BaseFile_PropertyAnnotation.java"); File patchFile = new File(testFileRootPath + "PatchFile_PropertyAnnotation.java"); - String mergedContents = new JavaMerger("", true).merge(baseFile, + // with override + String mergedContents = new JavaMerger("", false).merge(baseFile, + FileUtils.readFileToString(patchFile, StandardCharsets.UTF_8), "UTF-8"); + + assertThat(mergedContents).contains("@Column(name=\"USER\")"); + assertThat(mergedContents).contains("@Column(name=\"NAME\")"); + + // without override + + mergedContents = new JavaMerger("", true).merge(baseFile, FileUtils.readFileToString(patchFile, StandardCharsets.UTF_8), "UTF-8"); assertThat(mergedContents).contains("@Column(name= \"USERNAME\")"); assertThat(mergedContents).contains("@Column(name=\"NAME\")"); } + + /** + * Tests merging a Method annotation into the baseFile + * + * @throws IOException shouldn't happen + * @throws MergeException shouldn't happen either + */ + @Test + public void testMergeMethodAnnotation() throws IOException, MergeException { + + File baseFile = new File(testFileRootPath + "BaseFile_MethodAnnotation.java"); + File patchFile = new File(testFileRootPath + "PatchFile_MethodAnnotation.java"); + + // with override + String mergedContents = new JavaMerger("", true).merge(baseFile, + FileUtils.readFileToString(patchFile, StandardCharsets.UTF_8), "UTF-8"); + + assertThat(mergedContents).contains("@Column(name=\"USERNAME\")"); + assertThat(mergedContents).contains("@Column(name=\"USER\")"); + + // without override + mergedContents = new JavaMerger("", false).merge(baseFile, + FileUtils.readFileToString(patchFile, StandardCharsets.UTF_8), "UTF-8"); + + assertThat(mergedContents).contains("@Column(name=\"NAME\")"); + assertThat(mergedContents).contains("@Column(name=\"USER\")"); + } } diff --git a/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/BaseFile_ClassAnnotation.java b/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/BaseFile_ClassAnnotation.java index 2c57b628b5..1cda116c8c 100644 --- a/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/BaseFile_ClassAnnotation.java +++ b/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/BaseFile_ClassAnnotation.java @@ -2,6 +2,7 @@ import com.devonfw.application.jtqj.general.common.api.Visitor; +@javax.persistence.Table(name = "Visits") public class VisitorEntity extends ApplicationPersistenceEntity implements Visitor { private String username; diff --git a/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/BaseFile_MethodAnnotation.java b/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/BaseFile_MethodAnnotation.java new file mode 100644 index 0000000000..90fc95dd98 --- /dev/null +++ b/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/BaseFile_MethodAnnotation.java @@ -0,0 +1,21 @@ +package com.devonfw; + +/** + * Data access object for Visitor entities + */ +public class VisitorEntity extends ApplicationPersistenceEntity implements Visitor { + + private String username; + + private String name; + + @Column(name = "NAME") + public String getUsername() { + return this.username; + } + + public String getName() { + return this.Name; + } + +} diff --git a/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/BaseFile_PropertyAnnotation.java b/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/BaseFile_PropertyAnnotation.java index c0d9831a65..d7fc5453de 100644 --- a/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/BaseFile_PropertyAnnotation.java +++ b/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/BaseFile_PropertyAnnotation.java @@ -1,5 +1,6 @@ package com.devonfw.application.jtqj.general.dataaccess.api; +import javax.persistence.Entity; import com.devonfw.application.jtqj.general.common.api.Visitor; /** @@ -9,10 +10,11 @@ @javax.persistence.Table(name = "Visitor") public class VisitorEntity extends ApplicationPersistenceEntity implements Visitor { - private String username; + @Column(name = "USER") + private String username; - private String name; + private String name; - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; } diff --git a/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/PatchFile_MethodAnnotation.java b/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/PatchFile_MethodAnnotation.java new file mode 100644 index 0000000000..5bc2ef2cb3 --- /dev/null +++ b/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/test/resources/testdata/unittest/merger/PatchFile_MethodAnnotation.java @@ -0,0 +1,22 @@ +package com.devonfw; + +/** + * Data access object for Visitor entities + */ +public class VisitorEntity extends ApplicationPersistenceEntity implements Visitor { + + private String username; + + private String name; + + @Column(name = "USERNAME") + public String getUsername() { + return this.username; + } + + @Column(name = "USER") + public String getName() { + return this.Name; + } + +} From 3e851407ad59ab35fcc2f93712b46cce47594670 Mon Sep 17 00:00:00 2001 From: LarsReinken Date: Thu, 5 May 2022 16:27:51 +0200 Subject: [PATCH 4/4] Update JavaMerger.java --- .../com/devonfw/cobigen/javaplugin/merger/JavaMerger.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/main/java/com/devonfw/cobigen/javaplugin/merger/JavaMerger.java b/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/main/java/com/devonfw/cobigen/javaplugin/merger/JavaMerger.java index e4b35ffb83..19dbcae867 100644 --- a/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/main/java/com/devonfw/cobigen/javaplugin/merger/JavaMerger.java +++ b/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/src/main/java/com/devonfw/cobigen/javaplugin/merger/JavaMerger.java @@ -128,8 +128,8 @@ private ModifyableJavaClass merge(ModifyableJavaClass baseClass, ModifyableJavaC } /** - * @param baseAnnotations {@link JavaClass} - * @param patchAnnotations {@link JavaClass} + * @param baseAnnotations {@link JavaClass} a List of annotations originate from the base class + * @param patchAnnotations {@link JavaClass} a List of annotations originate from the patch class */ private List mergeAnnotation(List baseAnnotations, List patchAnnotations) {