diff --git a/core/src/main/java/org/mapstruct/Javadoc.java b/core/src/main/java/org/mapstruct/Javadoc.java
new file mode 100644
index 000000000..4b5d2fb83
--- /dev/null
+++ b/core/src/main/java/org/mapstruct/Javadoc.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Allows the definition of Javadoc comments in the MapStruct Mapper
generated class.
+ *
+ *
The annotation provides support for the usual Javadoc comments elements by defining analogous attributes.
+ * + * + *Please, note that at least one of these attributes must be specified.
+ * + *+ * For instance, the following definition; + *
+ *
+ * @Javadoc(
+ * value = "This is the description",
+ * authors = { "author1", "author2" },
+ * deprecated = "Use {@link OtherMapper} instead",
+ * since = "0.1"
+ * )
+ *
+ *
+ * + * will generate: + *
+ * + *
+ * /**
+ * * This is the description
+ * *
+ * * @author author1
+ * * @author author2
+ * *
+ * * @deprecated Use {@link OtherMapper} instead
+ * * @since 0.1
+ * */
+ *
+ *
+ * + * The entire Javadoc comment block can be passed directly: + *
+ *
+ * @Javadoc("This is the description\n"
+ * + "\n"
+ * + "@author author1\n"
+ * + "@author author2\n"
+ * + "\n"
+ * + "@deprecated Use {@link OtherMapper} instead\n"
+ * + "@since 0.1\n"
+ * )
+ *
+ *
+ *
+ * // or using Text Blocks
+ * @Javadoc(
+ * """
+ * This is the description
+ *
+ * @author author1
+ * @author author2
+ *
+ * @deprecated Use {@link OtherMapper} instead
+ * @since 0.1
+ * """
+ * )
+ *
+ */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.SOURCE)
+public @interface Javadoc {
+ /**
+ * Main Javadoc comment text block.
+ *
+ * @return Main Javadoc comment text block.
+ */
+ String value() default "";
+
+ /**
+ * List of authors of the code that it is being documented.
+ *
+ * It will generate a list of the Javadoc tool comment element @author
+ * with the different values and in the order provided.
+ *
+ * @return array of javadoc authors.
+ */
+ String[] authors() default { };
+
+ /**
+ * Specifies that the functionality that is being documented is deprecated.
+ *
+ * Corresponds to the @deprecated
Javadoc tool comment element.
+ *
+ * @return Deprecation message about the documented functionality
+ */
+ String deprecated() default "";
+
+ /**
+ * Specifies the version since the functionality that is being documented is available.
+ *
+ * Corresponds to the @since
Javadoc tool comment element.
+ *
+ * @return Version since the functionality is available
+ */
+ String since() default "";
+}
diff --git a/core/src/main/java/org/mapstruct/Mapper.java b/core/src/main/java/org/mapstruct/Mapper.java
index 60725cc44..8a6f48dad 100644
--- a/core/src/main/java/org/mapstruct/Mapper.java
+++ b/core/src/main/java/org/mapstruct/Mapper.java
@@ -74,6 +74,7 @@ import static org.mapstruct.SubclassExhaustiveStrategy.COMPILE_ERROR;
*
*
* @author Gunnar Morling
+ * @see Javadoc
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.CLASS)
diff --git a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc
index 8609ac4f7..eb3d5a80e 100644
--- a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc
+++ b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc
@@ -761,3 +761,103 @@ public class MyConverterImpl implements MyConverter {
}
----
====
+
+
+[[javadoc]]
+=== Adding Javadoc comments
+
+MapStruct provides support for defining Javadoc comments in the generated mapper implementation using the
+`org.mapstruct.Javadoc` annotation.
+
+This functionality could be relevant especially in situations where certain Javadoc standards need to be met or
+to deal with Javadoc validation constraints.
+
+The `@Javadoc` annotation defines attributes for the different Javadoc elements.
+
+Consider the following example:
+
+.Javadoc annotation example
+====
+[source, java, linenums]
+[subs="verbatim,attributes"]
+----
+@Mapper
+@Javadoc(
+ value = "This is the description",
+ authors = { "author1", "author2" },
+ deprecated = "Use {@link OtherMapper} instead",
+ since = "0.1"
+)
+public interface MyAnnotatedWithJavadocMapper {
+ //...
+}
+----
+====
+
+.Javadoc annotated generated mapper
+====
+[source, java, linenums]
+[subs="verbatim,attributes"]
+----
+/**
+* This is the description
+*
+* @author author1
+* @author author2
+*
+* @deprecated Use {@link OtherMapper} instead
+* @since 0.1
+*/
+public class MyAnnotatedWithJavadocMapperImpl implements MyAnnotatedWithJavadocMapper {
+ //...
+}
+----
+====
+
+The entire Javadoc comment block can be provided directly as well.
+
+.Javadoc annotation example with the entire Javadoc comment block provided directly
+====
+[source, java, linenums]
+[subs="verbatim,attributes"]
+----
+@Mapper
+@Javadoc(
+ "This is the description\n"
+ + "\n"
+ + "@author author1\n"
+ + "@author author2\n"
+ + "\n"
+ + "@deprecated Use {@link OtherMapper} instead\n"
+ + "@since 0.1\n"
+)
+public interface MyAnnotatedWithJavadocMapper {
+ //...
+}
+----
+====
+
+Or using Text blocks:
+
+.Javadoc annotation example with the entire Javadoc comment block provided directly using Text blocks
+====
+[source, java, linenums]
+[subs="verbatim,attributes"]
+----
+@Mapper
+@Javadoc(
+ """
+ This is the description
+
+ @author author1
+ @author author2
+
+ @deprecated Use {@link OtherMapper} instead
+ @since 0.1
+ """
+)
+public interface MyAnnotatedWithJavadocMapper {
+ //...
+}
+----
+====
\ No newline at end of file
diff --git a/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java
index 5caea8a00..9ac13184c 100644
--- a/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java
+++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java
@@ -21,6 +21,7 @@ import org.mapstruct.EnumMapping;
import org.mapstruct.InheritConfiguration;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.IterableMapping;
+import org.mapstruct.Javadoc;
import org.mapstruct.MapMapping;
import org.mapstruct.Mapper;
import org.mapstruct.MapperConfig;
@@ -75,6 +76,7 @@ import org.mapstruct.tools.gem.GemDefinition;
@GemDefinition(Context.class)
@GemDefinition(Builder.class)
@GemDefinition(Condition.class)
+@GemDefinition(Javadoc.class)
@GemDefinition(MappingControl.class)
@GemDefinition(MappingControls.class)
diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java
index df6ed9b2b..8348ecd84 100644
--- a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java
+++ b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java
@@ -253,6 +253,10 @@ public abstract class GeneratedType extends ModelElement {
constructor = null;
}
+ public Javadoc getJavadoc() {
+ return null;
+ }
+
protected void addIfImportRequired(Collection
+<#if javadoc??><#nt><@includeModel object=javadoc/>#if>
<#if !generatedTypeAvailable>/*#if>
@Generated(
value = "org.mapstruct.ap.MappingProcessor"<#if suppressGeneratorTimestamp == false>,
diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/Javadoc.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/Javadoc.ftl
new file mode 100644
index 000000000..89ac57b9e
--- /dev/null
+++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/Javadoc.ftl
@@ -0,0 +1,25 @@
+<#--
+
+ Copyright MapStruct Authors.
+
+ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+
+-->
+<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.Javadoc" -->
+/**
+<#list value?split("\n") as line><#nt>*<#if line?has_content> #if>${line?trim}
+#list>
+<#if !authors.isEmpty()>
+*
+<#list authors as author> <#nt>* @author ${author?trim}
+#list>
+#if>
+<#if deprecated?has_content>
+*
+<#nt>* @deprecated ${deprecated?trim}
+#if>
+<#if since?has_content>
+*
+<#nt>* @since ${since?trim}
+#if>
+<#nt> */
\ No newline at end of file
diff --git a/processor/src/test/java/org/mapstruct/ap/test/javadoc/ErroneousJavadocMapper.java b/processor/src/test/java/org/mapstruct/ap/test/javadoc/ErroneousJavadocMapper.java
new file mode 100644
index 000000000..39f6da289
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/javadoc/ErroneousJavadocMapper.java
@@ -0,0 +1,17 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.javadoc;
+
+import org.mapstruct.Javadoc;
+import org.mapstruct.Mapper;
+
+/**
+ * @author Jose Carlos Campanero Ortiz
+ */
+@Mapper
+@Javadoc
+public interface ErroneousJavadocMapper {
+}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/javadoc/JavadocAnnotatedWithAttributesMapper.java b/processor/src/test/java/org/mapstruct/ap/test/javadoc/JavadocAnnotatedWithAttributesMapper.java
new file mode 100644
index 000000000..eb6285ff1
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/javadoc/JavadocAnnotatedWithAttributesMapper.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.javadoc;
+
+import org.mapstruct.Javadoc;
+import org.mapstruct.Mapper;
+
+@Mapper
+@Javadoc(
+ value = "This is the description",
+ authors = { "author1", "author2" },
+ deprecated = "Use {@link OtherMapper} instead",
+ since = "0.1"
+)
+@Deprecated
+public interface JavadocAnnotatedWithAttributesMapper {
+
+}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/javadoc/JavadocAnnotatedWithValueMapper.java b/processor/src/test/java/org/mapstruct/ap/test/javadoc/JavadocAnnotatedWithValueMapper.java
new file mode 100644
index 000000000..150d7e5f7
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/javadoc/JavadocAnnotatedWithValueMapper.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.javadoc;
+
+import org.mapstruct.Javadoc;
+import org.mapstruct.Mapper;
+
+@Mapper
+@Javadoc("This is the description\n"
+ + "\n"
+ + "@author author1\n"
+ + "@author author2\n"
+ + "\n"
+ + "@deprecated Use {@link OtherMapper} instead\n"
+ + "@since 0.1\n")
+@Deprecated
+public interface JavadocAnnotatedWithValueMapper {
+
+}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/javadoc/JavadocTest.java b/processor/src/test/java/org/mapstruct/ap/test/javadoc/JavadocTest.java
new file mode 100644
index 000000000..316114389
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/javadoc/JavadocTest.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.javadoc;
+
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.mapstruct.ap.testutil.IssueKey;
+import org.mapstruct.ap.testutil.ProcessorTest;
+import org.mapstruct.ap.testutil.WithClasses;
+import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
+import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
+import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
+import org.mapstruct.ap.testutil.runner.GeneratedSource;
+
+/**
+ * @author Jose Carlos Campanero Ortiz
+ */
+@IssueKey("2987")
+class JavadocTest {
+
+ @RegisterExtension
+ final GeneratedSource generatedSource = new GeneratedSource();
+
+ @ProcessorTest
+ @WithClasses( { JavadocAnnotatedWithValueMapper.class } )
+ void javadocAnnotatedWithValueMapper() {
+ generatedSource.addComparisonToFixtureFor( JavadocAnnotatedWithValueMapper.class );
+ }
+
+ @ProcessorTest
+ @WithClasses( { JavadocAnnotatedWithAttributesMapper.class } )
+ void javadocAnnotatedWithAttributesMapper() {
+ generatedSource.addComparisonToFixtureFor( JavadocAnnotatedWithAttributesMapper.class );
+ }
+
+ @ProcessorTest
+ @IssueKey("2987")
+ @WithClasses({ ErroneousJavadocMapper.class })
+ @ExpectedCompilationOutcome(
+ value = CompilationResult.FAILED,
+ diagnostics = {
+ @Diagnostic(type = ErroneousJavadocMapper.class,
+ kind = javax.tools.Diagnostic.Kind.ERROR,
+ line = 15,
+ message = "'value', 'authors', 'deprecated' and 'since' are undefined in @Javadoc, "
+ + "define at least one of them.")
+ }
+ )
+ void shouldFailOnEmptyJavadocAnnotation() {
+ }
+
+}
diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/javadoc/JavadocAnnotatedWithAttributesMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/javadoc/JavadocAnnotatedWithAttributesMapperImpl.java
new file mode 100644
index 000000000..53b9a08e9
--- /dev/null
+++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/javadoc/JavadocAnnotatedWithAttributesMapperImpl.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.javadoc;
+
+import javax.annotation.processing.Generated;
+
+/**
+* This is the description
+*
+* @author author1
+* @author author2
+*
+* @deprecated Use {@link OtherMapper} instead
+*
+* @since 0.1
+*/
+@Generated(
+ value = "org.mapstruct.ap.MappingProcessor",
+ date = "2023-04-30T17:36:38+0200",
+ comments = "version: , compiler: javac, environment: Java 11.0.18 (Ubuntu)"
+)
+@Deprecated
+public class JavadocAnnotatedWithAttributesMapperImpl implements JavadocAnnotatedWithAttributesMapper {
+}
diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/javadoc/JavadocAnnotatedWithValueMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/javadoc/JavadocAnnotatedWithValueMapperImpl.java
new file mode 100644
index 000000000..7bcc54ca4
--- /dev/null
+++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/javadoc/JavadocAnnotatedWithValueMapperImpl.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.javadoc;
+
+import javax.annotation.processing.Generated;
+
+/**
+* This is the description
+*
+* @author author1
+* @author author2
+*
+* @deprecated Use {@link OtherMapper} instead
+* @since 0.1
+*
+*/
+@Generated(
+ value = "org.mapstruct.ap.MappingProcessor",
+ date = "2023-04-30T17:38:45+0200",
+ comments = "version: , compiler: javac, environment: Java 11.0.18 (Ubuntu)"
+)
+@Deprecated
+public class JavadocAnnotatedWithValueMapperImpl implements JavadocAnnotatedWithValueMapper {
+}