#94 Formatting, renaming test

This commit is contained in:
Gunnar Morling 2014-01-19 23:56:35 +01:00
parent e82277e0fc
commit 77e6890b00
10 changed files with 31 additions and 35 deletions

View File

@ -50,7 +50,7 @@ public class Mapping {
Map<String, List<Mapping>> mappings = new HashMap<String, List<Mapping>>(); Map<String, List<Mapping>> mappings = new HashMap<String, List<Mapping>>();
for ( MappingPrism mapping : mappingsAnnotation.value() ) { for ( MappingPrism mapping : mappingsAnnotation.value() ) {
if (!mappings.containsKey( mapping.source())) { if ( !mappings.containsKey( mapping.source() ) ) {
mappings.put( mapping.source(), new ArrayList<Mapping>() ); mappings.put( mapping.source(), new ArrayList<Mapping>() );
} }
mappings.get( mapping.source() ).add( fromMappingPrism( mapping, element ) ); mappings.get( mapping.source() ).add( fromMappingPrism( mapping, element ) );

View File

@ -22,7 +22,6 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Modifier; import javax.lang.model.element.Modifier;
@ -64,9 +63,10 @@ public class Method {
executable, executable,
parameters, parameters,
returnType, returnType,
Collections.<String, List<Mapping>> emptyMap(), Collections.<String, List<Mapping>>emptyMap(),
null, null,
null ); null
);
} }
private Method(Type declaringMapper, ExecutableElement executable, List<Parameter> parameters, Type returnType, private Method(Type declaringMapper, ExecutableElement executable, List<Parameter> parameters, Type returnType,
@ -207,8 +207,8 @@ public class Method {
} }
public Mapping getMapping(String targetPropertyName) { public Mapping getMapping(String targetPropertyName) {
for ( Map.Entry<String, List<Mapping>> entry : mappings.entrySet() ) { for ( Map.Entry<String, List<Mapping>> entry : mappings.entrySet() ) {
for ( Mapping mapping : entry.getValue()) { for ( Mapping mapping : entry.getValue() ) {
if ( mapping.getTargetName().equals( targetPropertyName ) ) { if ( mapping.getTargetName().equals( targetPropertyName ) ) {
return mapping; return mapping;
} }

View File

@ -220,9 +220,9 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Metho
Map<String, List<Mapping>> reversed = new HashMap<String, List<Mapping>>(); Map<String, List<Mapping>> reversed = new HashMap<String, List<Mapping>>();
for ( List<Mapping> mappingList : mappings.values() ) { for ( List<Mapping> mappingList : mappings.values() ) {
for (Mapping mapping : mappingList) { for ( Mapping mapping : mappingList ) {
if (!reversed.containsKey( mapping.getTargetName())) { if ( !reversed.containsKey( mapping.getTargetName() ) ) {
reversed.put( mapping.getTargetName(), new ArrayList<Mapping>()); reversed.put( mapping.getTargetName(), new ArrayList<Mapping>() );
} }
reversed.get( mapping.getTargetName() ).add( mapping.reverse() ); reversed.get( mapping.getTargetName() ).add( mapping.reverse() );
} }
@ -244,8 +244,8 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Metho
for ( ExecutableElement getter : sourceGetters ) { for ( ExecutableElement getter : sourceGetters ) {
List<Mapping> sourceMappings = method.getMappings().get( sourcePropertyName ); List<Mapping> sourceMappings = method.getMappings().get( sourcePropertyName );
if (method.getMappings().containsKey( sourcePropertyName ) ) { if ( method.getMappings().containsKey( sourcePropertyName ) ) {
for (Mapping sourceMapping : sourceMappings) { for ( Mapping sourceMapping : sourceMappings ) {
boolean mapsToOtherTarget = !sourceMapping.getTargetName().equals( targetPropertyName ); boolean mapsToOtherTarget = !sourceMapping.getTargetName().equals( targetPropertyName );
if ( executables.getPropertyName( getter ).equals( sourcePropertyName ) && !mapsToOtherTarget ) { if ( executables.getPropertyName( getter ).equals( sourcePropertyName ) && !mapsToOtherTarget ) {
return getPropertyMapping( return getPropertyMapping(
@ -259,8 +259,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Metho
} }
} }
} }
else if (executables.getPropertyName( getter ).equals( sourcePropertyName )) else if ( executables.getPropertyName( getter ).equals( sourcePropertyName ) ) {
{
return getPropertyMapping( return getPropertyMapping(
methods, methods,
method, method,
@ -399,7 +398,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Metho
boolean foundUnmappedProperty = false; boolean foundUnmappedProperty = false;
for ( List<Mapping> mappedProperties : method.getMappings().values() ) { for ( List<Mapping> mappedProperties : method.getMappings().values() ) {
for (Mapping mappedProperty : mappedProperties) { for ( Mapping mappedProperty : mappedProperties ) {
if ( mappedProperty.getSourceParameterName() != null ) { if ( mappedProperty.getSourceParameterName() != null ) {
Parameter sourceParameter = method.getSourceParameter( mappedProperty.getSourceParameterName() ); Parameter sourceParameter = method.getSourceParameter( mappedProperty.getSourceParameterName() );

View File

@ -18,13 +18,10 @@
*/ */
package org.mapstruct.ap.processor; package org.mapstruct.ap.processor;
import static javax.lang.model.util.ElementFilter.methodsIn;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.annotation.processing.Messager; import javax.annotation.processing.Messager;
import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Modifier; import javax.lang.model.element.Modifier;
@ -49,6 +46,8 @@ import org.mapstruct.ap.model.source.Method;
import org.mapstruct.ap.util.Executables; import org.mapstruct.ap.util.Executables;
import org.mapstruct.ap.util.TypeFactory; import org.mapstruct.ap.util.TypeFactory;
import static javax.lang.model.util.ElementFilter.methodsIn;
/** /**
* A {@link ModelElementProcessor} which retrieves a list of {@link Method}s * A {@link ModelElementProcessor} which retrieves a list of {@link Method}s
* representing all the mapping methods of the given bean mapper type as well as * representing all the mapping methods of the given bean mapper type as well as
@ -273,7 +272,7 @@ public class MethodRetrievalProcessor implements ModelElementProcessor<Void, Lis
MappingsPrism mappingsAnnotation = MappingsPrism.getInstanceOn( method ); MappingsPrism mappingsAnnotation = MappingsPrism.getInstanceOn( method );
if ( mappingAnnotation != null ) { if ( mappingAnnotation != null ) {
if (!mappings.containsKey( mappingAnnotation.source())) { if ( !mappings.containsKey( mappingAnnotation.source() ) ) {
mappings.put( mappingAnnotation.source(), new ArrayList<Mapping>() ); mappings.put( mappingAnnotation.source(), new ArrayList<Mapping>() );
} }
mappings.get( mappingAnnotation.source() ).add( Mapping.fromMappingPrism( mappingAnnotation, method ) ); mappings.get( mappingAnnotation.source() ).add( Mapping.fromMappingPrism( mappingAnnotation, method ) );

View File

@ -19,7 +19,6 @@
package org.mapstruct.ap.test.severaltargets; package org.mapstruct.ap.test.severaltargets;
/** /**
*
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
public class Source { public class Source {

View File

@ -18,28 +18,31 @@
*/ */
package org.mapstruct.ap.test.severaltargets; package org.mapstruct.ap.test.severaltargets;
import static org.fest.assertions.Assertions.assertThat;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase; import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import static org.fest.assertions.Assertions.assertThat;
import org.mapstruct.ap.testutil.IssueKey;
/** /**
* Test for the generation of implementation of abstract base classes. * Test for the generation of implementation of abstract base classes.
* *
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
@WithClasses({ Source.class, Target.class, SourceTargetMapper.class, TimeAndFormat.class, @WithClasses({
TimeAndFormatMapper.class }) Source.class, Target.class, SourceTargetMapper.class, TimeAndFormat.class,
public class MultipleSourcesTest extends MapperTestBase { TimeAndFormatMapper.class
})
public class SourcePropertyMapSeveralTimesTest extends MapperTestBase {
@Test @Test
@IssueKey("94") @IssueKey("94")
public void shouldMapMultipleSources() throws ParseException { public void shouldMapSameSourcePropertyToSeveralTargetProperties() throws ParseException {
Source source = new Source(); Source source = new Source();
String sourceFormat = "dd-MM-yyyy"; String sourceFormat = "dd-MM-yyyy";
SimpleDateFormat dateFormat = new SimpleDateFormat( sourceFormat ); SimpleDateFormat dateFormat = new SimpleDateFormat( sourceFormat );

View File

@ -24,7 +24,6 @@ import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
/** /**
*
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
@Mapper(uses = TimeAndFormatMapper.class) @Mapper(uses = TimeAndFormatMapper.class)
@ -32,9 +31,9 @@ public interface SourceTargetMapper {
SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );
@Mappings( @Mappings(
{ {
@Mapping(source = "timeAndFormat", target = "time"), @Mapping(source = "timeAndFormat", target = "time"),
@Mapping(source = "timeAndFormat", target = "format") @Mapping(source = "timeAndFormat", target = "format")
}) })
Target sourceToTarget( Source s ); Target sourceToTarget(Source s);
} }

View File

@ -21,7 +21,6 @@ package org.mapstruct.ap.test.severaltargets;
import java.util.Date; import java.util.Date;
/** /**
*
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
public class Target { public class Target {

View File

@ -21,7 +21,6 @@ package org.mapstruct.ap.test.severaltargets;
import java.util.Date; import java.util.Date;
/** /**
*
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
public class TimeAndFormat { public class TimeAndFormat {

View File

@ -21,7 +21,6 @@ package org.mapstruct.ap.test.severaltargets;
import java.util.Date; import java.util.Date;
/** /**
*
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
public class TimeAndFormatMapper { public class TimeAndFormatMapper {