#102 sharing mapper configuration and unit test

This commit is contained in:
sjaakd 2014-03-29 00:45:07 +01:00
parent a15cf08d24
commit c2138f2b8e
23 changed files with 768 additions and 17 deletions

View File

@ -44,11 +44,12 @@ public @interface Mapper {
/**
* How unmapped properties of the target type of a mapping should be
* reported.
* reported. The method overrides an unmappedTargetPolicy set in a central
* configuration set by {@link #mapperConfig() }
*
* @return The reporting policy for unmapped target properties.
*/
ReportingPolicy unmappedTargetPolicy() default ReportingPolicy.WARN;
ReportingPolicy unmappedTargetPolicy() default ReportingPolicy.DEFAULT;
/**
* Specifies the component model to which the generated mapper should
@ -66,8 +67,18 @@ public @interface Mapper {
* {@code jsr330}: the generated mapper is annotated with {@code @Named} and
* can be retrieved via {@code @Inject}</li>
* </ul>
*
* @return The component model for the generated mapper.
* The method overrides an unmappedTargetPolicy set in a central configuration set
* by {@link #mapperConfig() }
* @return The component model for the generated mapper.
*/
String componentModel() default "default";
/**
* Central mapper configuration, carrying the {@link MapperConfig} annotation
*
* @return a centralized class with {@link MapperConfig} annotation.
*/
Class<?> mapperConfig() default void.class;
}

View File

@ -0,0 +1,76 @@
/**
* Copyright 2012-2014 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;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.mapstruct.factory.Mappers;
/**
* Marks an interface as mapper interface and activates the generation of a
* mapper implementation for that interface.
*
* The {@link #unmappedTargetPolicy() } and {@link #componentModel() } an be overruled by a specific {@link Mapper}
* annotation. {@link #uses() } will be used in addition to what is specified in the {@link Mapper} annotation.
*
* @author Sjaak Derksen
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
public @interface MapperConfig {
/**
* The mapper types used by this mapper.
*
* @return The mapper types used by this mapper.
*/
Class<?>[] uses() default { };
/**
* How unmapped properties of the target type of a mapping should be
* reported.
*
* @return The reporting policy for unmapped target properties.
*/
ReportingPolicy unmappedTargetPolicy() default ReportingPolicy.DEFAULT;
/**
* Specifies the component model to which the generated mapper should
* adhere. Supported values are
* <ul>
* <li> {@code default}: the mapper uses no component model, instances are
* typically retrieved via {@link Mappers#getMapper(Class)}</li>
* <li>
* {@code cdi}: the generated mapper is an application-scoped CDI bean and
* can be retrieved via {@code @Inject}</li>
* <li>
* {@code spring}: the generated mapper is a Spring bean and
* can be retrieved via {@code @Autowired}</li>
* <li>
* {@code jsr330}: the generated mapper is annotated with {@code @Named} and
* can be retrieved via {@code @Inject}</li>
* </ul>
*
* @return The component model for the generated mapper.
*/
String componentModel() default "default";
}

View File

@ -42,5 +42,12 @@ public enum ReportingPolicy {
* A report with {@link Kind#ERROR} will be created for the given issue,
* causing the compilation to fail.
*/
ERROR;
ERROR,
/**
* A report with {@link Kind#WARNING} will be created for the given issue.
*
* This value is the default value and used to distinguish it from a user set WARNING level.
*/
DEFAULT;
}

View File

@ -29,7 +29,10 @@ import javax.tools.Diagnostic.Kind;
*/
public enum ReportingPolicy {
IGNORE( null, false, false ), WARN( Kind.WARNING, true, false ), ERROR( Kind.ERROR, true, true );
IGNORE( null, false, false ),
WARN( Kind.WARNING, true, false ),
ERROR( Kind.ERROR, true, true ),
DEFAULT( Kind.WARNING, true, false );
private final Diagnostic.Kind diagnosticKind;
private final boolean requiresReport;

View File

@ -26,6 +26,7 @@ import org.mapstruct.DecoratedWith;
import org.mapstruct.IterableMapping;
import org.mapstruct.MapMapping;
import org.mapstruct.Mapper;
import org.mapstruct.MapperConfig;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.Mappings;
@ -45,6 +46,7 @@ import org.mapstruct.TargetType;
@GeneratePrism(value = TargetType.class, publicAccess = true),
@GeneratePrism(value = MappingTarget.class, publicAccess = true),
@GeneratePrism(value = DecoratedWith.class, publicAccess = true),
@GeneratePrism(value = MapperConfig.class, publicAccess = true),
// external types
@GeneratePrism(value = XmlElementDecl.class, publicAccess = true)

View File

@ -27,7 +27,7 @@ import org.mapstruct.ap.model.Mapper;
import org.mapstruct.ap.model.MapperReference;
import org.mapstruct.ap.model.common.TypeFactory;
import org.mapstruct.ap.option.OptionsHelper;
import org.mapstruct.ap.prism.MapperPrism;
import org.mapstruct.ap.util.MapperSettings;
/**
* An {@link ModelElementProcessor} which converts the given {@link Mapper}
@ -45,7 +45,7 @@ public abstract class AnnotationBasedComponentModelProcessor implements ModelEle
public Mapper process(ProcessorContext context, TypeElement mapperTypeElement, Mapper mapper) {
this.typeFactory = context.getTypeFactory();
String componentModel = MapperPrism.getInstanceOn( mapperTypeElement ).componentModel();
String componentModel = MapperSettings.getInstanceOn( mapperTypeElement ).componentModel();
String effectiveComponentModel = OptionsHelper.getEffectiveComponentModel(
context.getOptions(),
componentModel

View File

@ -71,6 +71,7 @@ import org.mapstruct.ap.prism.DecoratedWithPrism;
import org.mapstruct.ap.prism.MapperPrism;
import org.mapstruct.ap.util.Executables;
import org.mapstruct.ap.util.Filters;
import org.mapstruct.ap.util.MapperSettings;
import org.mapstruct.ap.util.Strings;
/**
@ -151,9 +152,9 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
* @return The effective policy for reporting unmapped getReturnType properties.
*/
private ReportingPolicy getEffectiveUnmappedTargetPolicy(TypeElement element) {
MapperPrism mapperPrism = MapperPrism.getInstanceOn( element );
boolean setViaAnnotation = mapperPrism.values.unmappedTargetPolicy() != null;
ReportingPolicy annotationValue = ReportingPolicy.valueOf( mapperPrism.unmappedTargetPolicy() );
MapperSettings mapperSettings = MapperSettings.getInstanceOn( element );
boolean setViaAnnotation = mapperSettings.isSetUnmappedTargetPolicy();
ReportingPolicy annotationValue = ReportingPolicy.valueOf( mapperSettings.unmappedTargetPolicy() );
if ( setViaAnnotation ||
options.getUnmappedTargetPolicy() == null ) {
@ -243,7 +244,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
List<MapperReference> mapperReferences = new LinkedList<MapperReference>();
List<String> variableNames = new LinkedList<String>();
MapperPrism mapperPrism = MapperPrism.getInstanceOn( element );
MapperSettings mapperPrism = MapperSettings.getInstanceOn( element );
for ( TypeMirror usedMapper : mapperPrism.uses() ) {
DefaultMapperReference mapperReference = DefaultMapperReference.getInstance(

View File

@ -44,10 +44,10 @@ import org.mapstruct.ap.model.source.Mapping;
import org.mapstruct.ap.model.source.SourceMethod;
import org.mapstruct.ap.prism.IterableMappingPrism;
import org.mapstruct.ap.prism.MapMappingPrism;
import org.mapstruct.ap.prism.MapperPrism;
import org.mapstruct.ap.prism.MappingPrism;
import org.mapstruct.ap.prism.MappingsPrism;
import org.mapstruct.ap.util.AnnotationProcessingException;
import org.mapstruct.ap.util.MapperSettings;
/**
* A {@link ModelElementProcessor} which retrieves a list of {@link SourceMethod}s
@ -98,14 +98,14 @@ public class MethodRetrievalProcessor implements ModelElementProcessor<Void, Lis
//Add all methods of used mappers in order to reference them in the aggregated model
if ( mapperRequiresImplementation ) {
MapperPrism mapperPrism = MapperPrism.getInstanceOn( element );
if ( !mapperPrism.isValid ) {
MapperSettings mapperSettings = MapperSettings.getInstanceOn( element );
if ( !mapperSettings.isValid() ) {
throw new AnnotationProcessingException(
"Couldn't retrieve @Mapper annotation", element, mapperPrism.mirror
"Couldn't retrieve @Mapper annotation", element, mapperSettings.getAnnotationMirror()
);
}
for ( TypeMirror usedMapper : mapperPrism.uses() ) {
for ( TypeMirror usedMapper : mapperSettings.uses() ) {
methods.addAll(
retrieveMethods(
(TypeElement) ( (DeclaredType) usedMapper ).asElement(),

View File

@ -0,0 +1,108 @@
/**
* Copyright 2012-2014 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.util;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import org.mapstruct.ap.option.ReportingPolicy;
import org.mapstruct.ap.prism.MapperConfigPrism;
import org.mapstruct.ap.prism.MapperPrism;
/**
*
* @author Sjaak Derksen
*/
public class MapperSettings {
private final MapperPrism mapperPrism;
private final MapperConfigPrism mapperConfigPrism;
public static MapperSettings getInstanceOn(Element e) {
return new MapperSettings( MapperPrism.getInstanceOn( e ) );
}
public static MapperSettings getInstance(AnnotationMirror mirror ) {
return new MapperSettings( MapperPrism.getInstance( mirror ) );
}
private MapperSettings( MapperPrism mapperPrism ) {
this.mapperPrism = mapperPrism;
TypeMirror typeMirror = mapperPrism.mapperConfig();
if ( typeMirror.getKind().equals( TypeKind.DECLARED ) ) {
this.mapperConfigPrism = MapperConfigPrism.getInstanceOn( ( (DeclaredType) typeMirror ).asElement() );
}
else {
this.mapperConfigPrism = null;
}
}
public List<TypeMirror> uses() {
Set<TypeMirror> uses = new HashSet<TypeMirror>( mapperPrism.uses() );
if ( mapperConfigPrism != null ) {
uses.addAll( mapperConfigPrism.uses() );
}
return new ArrayList<TypeMirror>( uses );
}
public String unmappedTargetPolicy() {
if ( !ReportingPolicy.valueOf( mapperPrism.unmappedTargetPolicy() ).equals( ReportingPolicy.DEFAULT ) ) {
// it is not the default configuration
return mapperPrism.unmappedTargetPolicy();
}
else if ( mapperConfigPrism != null &&
!ReportingPolicy.valueOf( mapperConfigPrism.unmappedTargetPolicy())
.equals( ReportingPolicy.DEFAULT ) ) {
return mapperConfigPrism.unmappedTargetPolicy();
}
else {
return ReportingPolicy.WARN.name();
}
}
public String componentModel() {
if ( !mapperPrism.componentModel().equals( "default" ) ) {
return mapperPrism.componentModel();
}
else if ( mapperConfigPrism != null ) {
return mapperConfigPrism.componentModel();
}
else {
return "default";
}
}
public boolean isValid() {
return mapperPrism.isValid;
}
public boolean isSetUnmappedTargetPolicy() {
return mapperPrism.values.unmappedTargetPolicy() != null;
}
public AnnotationMirror getAnnotationMirror() {
return mapperPrism.mirror;
}
}

View File

@ -0,0 +1,27 @@
/**
* Copyright 2012-2014 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.mapperconfig;
/**
*
* @author Sjaak Derksen
*/
public class BarDto {
}

View File

@ -0,0 +1,27 @@
/**
* Copyright 2012-2014 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.mapperconfig;
/**
*
* @author Sjaak Derksen
*/
public class BarEntity {
}

View File

@ -0,0 +1,31 @@
/**
* Copyright 2012-2014 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.mapperconfig;
import org.mapstruct.MapperConfig;
import org.mapstruct.ReportingPolicy;
/**
*
* @author Sjaak Derksen
*/
@MapperConfig(uses = { CustomMapperViaMapperConfig.class }, unmappedTargetPolicy = ReportingPolicy.ERROR )
public class CentralConfig {
}

View File

@ -0,0 +1,86 @@
/**
* Copyright 2012-2014 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.mapperconfig;
import static org.fest.assertions.Assertions.assertThat;
import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
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.testng.annotations.Test;
/**
*
* @author Sjaak Derksen
*/
@IssueKey( "102" )
@WithClasses( {
Source.class,
Target.class,
FooDto.class,
FooEntity.class,
CentralConfig.class,
CustomMapperViaMapper.class,
CustomMapperViaMapperConfig.class,
SourceTargetMapper.class
} )
public class ConfigTest extends MapperTestBase {
@Test
@WithClasses( { Target.class, SourceTargetMapper.class } )
public void shouldUseCustomMapperViaMapperForFooToEntity() {
Target target = SourceTargetMapper.INSTANCE.toTarget( new Source( new FooDto() ) );
assertThat( target.getFoo() ).isNotNull();
assertThat( target.getFoo().getCreatedBy() ).isEqualTo( CustomMapperViaMapper.class.getSimpleName() );
}
@Test
@WithClasses( { Target.class, SourceTargetMapper.class } )
public void shouldUseCustomMapperViaMapperConfigForFooToDto() {
Source source = SourceTargetMapper.INSTANCE.toSource( new Target( new FooEntity() ) );
assertThat( source.getFoo() ).isNotNull();
assertThat( source.getFoo().getCreatedBy() ).isEqualTo( CustomMapperViaMapperConfig.class.getSimpleName() );
}
@Test
@WithClasses( { TargetNoFoo.class, SourceTargetMapperWarn.class } )
@ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED,
diagnostics = {
@Diagnostic(type = SourceTargetMapperWarn.class,
kind = javax.tools.Diagnostic.Kind.WARNING, line = 37,
messageRegExp = "Unmapped target property: \"noFoo\"")
})
public void shouldUseWARNViaMapper() {
}
@Test
@WithClasses( { TargetNoFoo.class, SourceTargetMapperError.class } )
@ExpectedCompilationOutcome(value = CompilationResult.FAILED,
diagnostics = {
@Diagnostic(type = SourceTargetMapperError.class,
kind = javax.tools.Diagnostic.Kind.ERROR, line = 33,
messageRegExp = "Unmapped target property: \"noFoo\"")
})
public void shouldUseERRORViaMapperConfig() {
}
}

View File

@ -0,0 +1,30 @@
/**
* Copyright 2012-2014 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.mapperconfig;
/**
*
* @author Sjaak Derksen
*/
public class CustomMapperViaMapper {
public FooEntity toFooEntity( FooDto dto ) {
return new FooEntity( this.getClass().getSimpleName() );
}
}

View File

@ -0,0 +1,30 @@
/**
* Copyright 2012-2014 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.mapperconfig;
/**
*
* @author Sjaak Derksen
*/
public class CustomMapperViaMapperConfig {
public FooDto toFooDto(FooEntity foo) {
return new FooDto( this.getClass().getSimpleName() );
}
}

View File

@ -0,0 +1,40 @@
/**
* Copyright 2012-2014 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.mapperconfig;
/**
*
* @author Sjaak Derksen
*/
public class FooDto {
private String createdBy;
public FooDto() {
}
public FooDto( String createdBy ) {
this.createdBy = createdBy;
}
public String getCreatedBy() {
return createdBy;
}
}

View File

@ -0,0 +1,40 @@
/**
* Copyright 2012-2014 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.mapperconfig;
/**
*
* @author Sjaak Derksen
*/
public class FooEntity {
private String createdBy;
public FooEntity() {
}
public FooEntity( String createdBy ) {
this.createdBy = createdBy;
}
public String getCreatedBy() {
return createdBy;
}
}

View File

@ -0,0 +1,44 @@
/**
* Copyright 2012-2014 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.mapperconfig;
/**
*
* @author Sjaak Derksen
*/
public class Source {
private FooDto foo;
public Source( ) {
}
public Source( FooDto foo ) {
this.foo = foo;
}
public FooDto getFoo() {
return foo;
}
public void setFoo( FooDto foo ) {
this.foo = foo;
}
}

View File

@ -0,0 +1,35 @@
/**
* Copyright 2012-2014 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.mapperconfig;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
/**
*
* @author Sjaak Derksen
*/
@Mapper(uses = { CustomMapperViaMapper.class }, mapperConfig = CentralConfig.class )
public interface SourceTargetMapper {
SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );
Target toTarget( Source source );
Source toSource( Target target );
}

View File

@ -0,0 +1,34 @@
/**
* Copyright 2012-2014 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.mapperconfig;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
/**
*
* @author Sjaak Derksen
*/
@Mapper(uses = { CustomMapperViaMapper.class }, mapperConfig = CentralConfig.class )
public interface SourceTargetMapperError {
SourceTargetMapperError INSTANCE = Mappers.getMapper( SourceTargetMapperError.class );
TargetNoFoo toTarget( Source source );
}

View File

@ -0,0 +1,38 @@
/**
* Copyright 2012-2014 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.mapperconfig;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;
/**
*
* @author Sjaak Derksen
*/
@Mapper(uses = { CustomMapperViaMapper.class },
mapperConfig = CentralConfig.class,
unmappedTargetPolicy = ReportingPolicy.WARN
)
public interface SourceTargetMapperWarn {
SourceTargetMapperWarn INSTANCE = Mappers.getMapper( SourceTargetMapperWarn.class );
TargetNoFoo toTarget( Source source );
}

View File

@ -0,0 +1,44 @@
/**
* Copyright 2012-2014 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.mapperconfig;
/**
*
* @author Sjaak Derksen
*/
public class Target {
private FooEntity foo;
public Target() {
}
public Target( FooEntity foo ) {
this.foo = foo;
}
public FooEntity getFoo() {
return foo;
}
public void setFoo( FooEntity foo ) {
this.foo = foo;
}
}

View File

@ -0,0 +1,37 @@
/**
* Copyright 2012-2014 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.mapperconfig;
/**
*
* @author Sjaak Derksen
*/
public class TargetNoFoo {
private FooEntity noFoo;
public FooEntity getNoFoo() {
return noFoo;
}
public void setNoFoo( FooEntity noFoo ) {
this.noFoo = noFoo;
}
}