diff --git a/README.md b/README.md index 57f246d..3f44c83 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ To learn more about MapStruct have a look at the [mapstruct](https://github.com/ * More than one `source` in `@Mapping` annotation defined with quick fixes: Remove `source`. Remove `constant`. Remove `expression`. Use `constant` as `defaultValue`. Use `expression` as `defaultExpression`. * More than one default source in `@Mapping` annotation defined with quick fixes: Remove `defaultValue`. Remove `defaultExpression`. * `target` mapped more than once by `@Mapping` annotations with quick fixes: Remove annotation and change target property. + * `*` used as a source in `@Mapping` annotation with quick fixes: Replace `*` with method parameter name. ## Requirements diff --git a/description.html b/description.html index e658e17..ef0e473 100644 --- a/description.html +++ b/description.html @@ -42,6 +42,7 @@
source
in @Mapping
annotation defined with quick fixes: Remove source
. Remove constant
. Remove expression
. Use constant
as defaultValue
. Use expression
as defaultExpression
.@Mapping
annotation defined with quick fixes: Remove defaultValue
. Remove defaultExpression
.target
mapped more than once by @Mapping
annotations with quick fixes: Remove annotation and change target property.*
used as a source in @Mapping
annotations with quick fixes: Replace *
with method parameter name.
+ This inspection reports when "." is used as a source in @Mapping
+
+
+//wrong
+@Mapper
+public interface EmployeeMapper {
+ @Mapping(target = "dto", source = ".")
+ Employee toEmployee(EmployeeDto employeeDto, @Context CycleAvoidingMappingContext context);
+}
+
+
++
+//correct
+@Mapper
+public interface EmployeeMapper {
+ @Mapping(source = "employeeDto", target = "dto")
+ Employee toEmployee(EmployeeDto employeeDto, @Context CycleAvoidingMappingContext context);
+}
+
+
+
+
+
diff --git a/src/main/resources/org/mapstruct/intellij/messages/MapStructBundle.properties b/src/main/resources/org/mapstruct/intellij/messages/MapStructBundle.properties
index 8664108..d9311be 100644
--- a/src/main/resources/org/mapstruct/intellij/messages/MapStructBundle.properties
+++ b/src/main/resources/org/mapstruct/intellij/messages/MapStructBundle.properties
@@ -27,6 +27,7 @@ inspection.wrong.map.mapping.map.key=Key must be of type String for mapping Map
inspection.wrong.map.mapping.map.key.change.to.string=Change key type to String
inspection.target.property.mapped.more.than.once=Target property ''{0}'' must not be mapped more than once.
inspection.target.property.mapped.more.than.once.title=Target properties must not be mapped more than once.
+inspection.source.property.this.used=''.'' should not be used as a source.
intention.add.ignore.all.unmapped.target.properties=Add ignore all unmapped target properties
intention.add.ignore.unmapped.target.property=Add ignore unmapped target property
intention.add.unmapped.target.property=Add unmapped target property
@@ -38,6 +39,7 @@ intention.wrong.map.mapping.map.type.raw=Add type to Map for mapping Map to Bean
intention.wrong.map.mapping.map.key=Use Map with key of type String for mapping Map to Bean
intention.remove.annotation=Remove {0} annotation
intention.change.target.property=Change target property
+intention.replace.source.property=Replace source ''.'' with ''{0}''
plugin.settings.title=MapStruct
plugin.settings.quickFix.title=Quick fix properties
plugin.settings.quickFix.preferSourceBeforeTargetInMapping=Prefer source before target in @Mapping
diff --git a/src/test/java/org/mapstruct/intellij/inspection/ThisUsedAsSourcePropertyInspectionTest.java b/src/test/java/org/mapstruct/intellij/inspection/ThisUsedAsSourcePropertyInspectionTest.java
new file mode 100644
index 0000000..acde20e
--- /dev/null
+++ b/src/test/java/org/mapstruct/intellij/inspection/ThisUsedAsSourcePropertyInspectionTest.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at https://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.intellij.inspection;
+
+import com.intellij.codeInsight.intention.IntentionAction;
+import com.intellij.codeInspection.LocalInspectionTool;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * @author hduelme
+ */
+public class ThisUsedAsSourcePropertyInspectionTest extends BaseInspectionTest {
+ @Override
+ protected @NotNull Class extends LocalInspectionTool> getInspection() {
+ return ThisUsedAsSourcePropertyInspection.class;
+ }
+
+ public void testThisUsedAsSourcePropertyInspection() {
+ doTest();
+ List