Skip to content

Commit

Permalink
mapstruct#1027 do not consider Inherit(Inverse)Configuration in used …
Browse files Browse the repository at this point in the history
…mappers
  • Loading branch information
sjaakd committed Jan 8, 2017
1 parent a69627d commit 1ee4731
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
10 changes: 10 additions & 0 deletions documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -1869,6 +1869,11 @@ In case more than one method is applicable as source for the inheritance, the me

A method can use `@InheritConfiguration` and override or amend the configuration by additionally applying `@Mapping`, `@BeanMapping`, etc.

[NOTE]
====
`@InheritConfiguration` cannot refer to methods in a used mapper.
====

[[inverse-mappings]]
=== Inverse mappings

Expand Down Expand Up @@ -1905,6 +1910,11 @@ If multiple methods qualify, the method from which to inherit the configuration

Expressions and constants are excluded (silently ignored). Reverse mapping of nested source properties is experimental as of the 1.1.0.Beta2. Reverse mapping will take place automatically when the source property name and target property name are identical. Otherwise, `@Mapping` should specify both the target name and source name. In all cases, a suitable mapping method needs to be in place for the reverse mapping.

[NOTE]
====
`@InheritInverseConfiguration` cannot refer to methods in a used mapper.
====

[[shared-configurations]]
=== Shared configurations

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ public Mapping getSingleMappingByTargetPropertyName(String targetPropertyName) {
}

public boolean reverses(SourceMethod method) {
return isAbstract()
return getDeclaringMapper() == null
&& isAbstract()
&& getSourceParameters().size() == 1 && method.getSourceParameters().size() == 1
&& equals( first( getSourceParameters() ).getType(), method.getResultType() )
&& equals( getResultType(), first( method.getSourceParameters() ).getType() );
Expand All @@ -347,7 +348,8 @@ && equals( first( getSourceParameters() ).getType(), first( method.getSourcePara
}

public boolean canInheritFrom(SourceMethod method) {
return method.isAbstract()
return method.getDeclaringMapper() == null
&& method.isAbstract()
&& isMapMapping() == method.isMapMapping()
&& isIterableMapping() == method.isIterableMapping()
&& isEnumMapping() == method.isEnumMapping()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* @author Andreas Gudian
*/
@Mapper(
uses = NotToBeUsedMapper.class,
config = AutoInheritedConfig.class,
mappingInheritanceStrategy = MappingInheritanceStrategy.EXPLICIT
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
CarEntity.class,
CarMapperWithAutoInheritance.class,
CarMapperWithExplicitInheritance.class,
AutoInheritedConfig.class
AutoInheritedConfig.class,
NotToBeUsedMapper.class
})
@IssueKey("168")
public class InheritFromConfigTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
* and/or other contributors as indicated by the @authors tag. See the
* copyright.txt file in the distribution for a full listing of all
* contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.ap.test.inheritfromconfig;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

/**
*
* @author Sjaak Derksen
*/
@Mapper
public interface NotToBeUsedMapper {

@Mappings({
@Mapping(target = "primaryKey", ignore = true),
@Mapping(target = "auditTrail", ignore = true),
@Mapping(target = "color", ignore = true)
})
CarEntity toCarEntity(CarDto carDto);
}

0 comments on commit 1ee4731

Please sign in to comment.