diff --git a/processor/src/main/java/org/mapstruct/ap/model/source/Method.java b/processor/src/main/java/org/mapstruct/ap/model/source/Method.java
index 05736cf33..eece09af2 100644
--- a/processor/src/main/java/org/mapstruct/ap/model/source/Method.java
+++ b/processor/src/main/java/org/mapstruct/ap/model/source/Method.java
@@ -32,6 +32,10 @@ import org.mapstruct.ap.util.Strings;
/**
* Represents a mapping method with source and target type and the mappings between the properties of source and target
* type.
+ *
+ * A method can either be configured by itself or by another method for the inverse mapping direction (one of
+ * {@link #setMappings(Map)}, {@link #setIterableMapping(IterableMapping)} or {@link #setMapMapping(MapMapping)} will be
+ * called in this case).
*
* @author Gunnar Morling
*/
@@ -40,13 +44,14 @@ public class Method {
private final Type declaringMapper;
private final ExecutableElement executable;
private final List parameters;
+ private final Parameter targetParameter;
private final Type returnType;
private Map> mappings;
private IterableMapping iterableMapping;
private MapMapping mapMapping;
- private final Parameter targetParameter;
+ private boolean configuredByReverseMappingMethod = false;
public static Method forMethodRequiringImplementation(ExecutableElement executable, List parameters,
Type returnType, Map> mappings,
@@ -150,6 +155,7 @@ public class Method {
public void setMappings(Map> mappings) {
this.mappings = mappings;
+ this.configuredByReverseMappingMethod = true;
}
public IterableMapping getIterableMapping() {
@@ -158,6 +164,7 @@ public class Method {
public void setIterableMapping(IterableMapping iterableMapping) {
this.iterableMapping = iterableMapping;
+ this.configuredByReverseMappingMethod = true;
}
public MapMapping getMapMapping() {
@@ -166,6 +173,7 @@ public class Method {
public void setMapMapping(MapMapping mapMapping) {
this.mapMapping = mapMapping;
+ this.configuredByReverseMappingMethod = true;
}
public boolean reverses(Method method) {
@@ -188,6 +196,15 @@ public class Method {
&& getResultType().isMapType();
}
+ /**
+ * Whether this method is configured by itself or by the corresponding reverse mapping method.
+ *
+ * @return {@code true} if this method is configured by itself, {@code false} otherwise.
+ */
+ public boolean isConfiguredByReverseMappingMethod() {
+ return configuredByReverseMappingMethod;
+ }
+
private boolean equals(Object o1, Object o2) {
return ( o1 == null && o2 == null ) || ( o1 != null ) && o1.equals( o2 );
}
diff --git a/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java
index 7297955e2..244655857 100644
--- a/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java
+++ b/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java
@@ -27,7 +27,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
-
import javax.annotation.processing.Messager;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
@@ -377,7 +376,7 @@ public class MapperCreationProcessor implements ModelElementProcessor targetAccessors = filters.setterMethodsIn(
+ List getters = filters.getterMethodsIn(
elementUtils.getAllMembers( parameterTypeElement )
);
- targetAccessors.addAll(
- filters.alternativeTargetAccessorMethodsIn(
- elementUtils.getAllMembers( parameterTypeElement )
- )
- );
- return executables.getPropertyNames( targetAccessors ).contains( propertyName );
+
+ return executables.getPropertyNames( getters ).contains( propertyName );
}
private boolean reportErrorIfMappedPropertiesDontExist(Method method) {
+ // only report errors if this method itself is configured
+ if ( method.isConfiguredByReverseMappingMethod() ) {
+ return true;
+ }
+
TypeElement resultTypeElement = method.getResultType().getTypeElement();
List targetAccessors = filters.setterMethodsIn(
elementUtils.getAllMembers( resultTypeElement )
@@ -431,7 +431,7 @@ public class MapperCreationProcessor implements ModelElementProcessor