mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#94 Formatting, renaming test
This commit is contained in:
parent
e82277e0fc
commit
77e6890b00
@ -50,7 +50,7 @@ public class Mapping {
|
||||
Map<String, List<Mapping>> mappings = new HashMap<String, List<Mapping>>();
|
||||
|
||||
for ( MappingPrism mapping : mappingsAnnotation.value() ) {
|
||||
if (!mappings.containsKey( mapping.source())) {
|
||||
if ( !mappings.containsKey( mapping.source() ) ) {
|
||||
mappings.put( mapping.source(), new ArrayList<Mapping>() );
|
||||
}
|
||||
mappings.get( mapping.source() ).add( fromMappingPrism( mapping, element ) );
|
||||
|
@ -22,7 +22,6 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.Modifier;
|
||||
|
||||
@ -64,9 +63,10 @@ public class Method {
|
||||
executable,
|
||||
parameters,
|
||||
returnType,
|
||||
Collections.<String, List<Mapping>> emptyMap(),
|
||||
Collections.<String, List<Mapping>>emptyMap(),
|
||||
null,
|
||||
null );
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
private Method(Type declaringMapper, ExecutableElement executable, List<Parameter> parameters, Type returnType,
|
||||
@ -207,8 +207,8 @@ public class Method {
|
||||
}
|
||||
|
||||
public Mapping getMapping(String targetPropertyName) {
|
||||
for ( Map.Entry<String, List<Mapping>> entry : mappings.entrySet() ) {
|
||||
for ( Mapping mapping : entry.getValue()) {
|
||||
for ( Map.Entry<String, List<Mapping>> entry : mappings.entrySet() ) {
|
||||
for ( Mapping mapping : entry.getValue() ) {
|
||||
if ( mapping.getTargetName().equals( targetPropertyName ) ) {
|
||||
return mapping;
|
||||
}
|
||||
|
@ -220,9 +220,9 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Metho
|
||||
Map<String, List<Mapping>> reversed = new HashMap<String, List<Mapping>>();
|
||||
|
||||
for ( List<Mapping> mappingList : mappings.values() ) {
|
||||
for (Mapping mapping : mappingList) {
|
||||
if (!reversed.containsKey( mapping.getTargetName())) {
|
||||
reversed.put( mapping.getTargetName(), new ArrayList<Mapping>());
|
||||
for ( Mapping mapping : mappingList ) {
|
||||
if ( !reversed.containsKey( mapping.getTargetName() ) ) {
|
||||
reversed.put( mapping.getTargetName(), new ArrayList<Mapping>() );
|
||||
}
|
||||
reversed.get( mapping.getTargetName() ).add( mapping.reverse() );
|
||||
}
|
||||
@ -244,8 +244,8 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Metho
|
||||
for ( ExecutableElement getter : sourceGetters ) {
|
||||
|
||||
List<Mapping> sourceMappings = method.getMappings().get( sourcePropertyName );
|
||||
if (method.getMappings().containsKey( sourcePropertyName ) ) {
|
||||
for (Mapping sourceMapping : sourceMappings) {
|
||||
if ( method.getMappings().containsKey( sourcePropertyName ) ) {
|
||||
for ( Mapping sourceMapping : sourceMappings ) {
|
||||
boolean mapsToOtherTarget = !sourceMapping.getTargetName().equals( targetPropertyName );
|
||||
if ( executables.getPropertyName( getter ).equals( sourcePropertyName ) && !mapsToOtherTarget ) {
|
||||
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(
|
||||
methods,
|
||||
method,
|
||||
@ -399,7 +398,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Metho
|
||||
boolean foundUnmappedProperty = false;
|
||||
|
||||
for ( List<Mapping> mappedProperties : method.getMappings().values() ) {
|
||||
for (Mapping mappedProperty : mappedProperties) {
|
||||
for ( Mapping mappedProperty : mappedProperties ) {
|
||||
if ( mappedProperty.getSourceParameterName() != null ) {
|
||||
Parameter sourceParameter = method.getSourceParameter( mappedProperty.getSourceParameterName() );
|
||||
|
||||
|
@ -18,13 +18,10 @@
|
||||
*/
|
||||
package org.mapstruct.ap.processor;
|
||||
|
||||
import static javax.lang.model.util.ElementFilter.methodsIn;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.processing.Messager;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
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.TypeFactory;
|
||||
|
||||
import static javax.lang.model.util.ElementFilter.methodsIn;
|
||||
|
||||
/**
|
||||
* 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
|
||||
@ -273,7 +272,7 @@ public class MethodRetrievalProcessor implements ModelElementProcessor<Void, Lis
|
||||
MappingsPrism mappingsAnnotation = MappingsPrism.getInstanceOn( method );
|
||||
|
||||
if ( mappingAnnotation != null ) {
|
||||
if (!mappings.containsKey( mappingAnnotation.source())) {
|
||||
if ( !mappings.containsKey( mappingAnnotation.source() ) ) {
|
||||
mappings.put( mappingAnnotation.source(), new ArrayList<Mapping>() );
|
||||
}
|
||||
mappings.get( mappingAnnotation.source() ).add( Mapping.fromMappingPrism( mappingAnnotation, method ) );
|
||||
|
@ -19,7 +19,6 @@
|
||||
package org.mapstruct.ap.test.severaltargets;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class Source {
|
||||
|
@ -18,28 +18,31 @@
|
||||
*/
|
||||
package org.mapstruct.ap.test.severaltargets;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import org.mapstruct.ap.testutil.IssueKey;
|
||||
import org.mapstruct.ap.testutil.MapperTestBase;
|
||||
import org.mapstruct.ap.testutil.WithClasses;
|
||||
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.
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
@WithClasses({ Source.class, Target.class, SourceTargetMapper.class, TimeAndFormat.class,
|
||||
TimeAndFormatMapper.class })
|
||||
public class MultipleSourcesTest extends MapperTestBase {
|
||||
@WithClasses({
|
||||
Source.class, Target.class, SourceTargetMapper.class, TimeAndFormat.class,
|
||||
TimeAndFormatMapper.class
|
||||
})
|
||||
public class SourcePropertyMapSeveralTimesTest extends MapperTestBase {
|
||||
|
||||
@Test
|
||||
@IssueKey("94")
|
||||
public void shouldMapMultipleSources() throws ParseException {
|
||||
public void shouldMapSameSourcePropertyToSeveralTargetProperties() throws ParseException {
|
||||
Source source = new Source();
|
||||
String sourceFormat = "dd-MM-yyyy";
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat( sourceFormat );
|
@ -24,7 +24,6 @@ import org.mapstruct.Mappings;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
@Mapper(uses = TimeAndFormatMapper.class)
|
||||
@ -32,9 +31,9 @@ public interface SourceTargetMapper {
|
||||
SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );
|
||||
|
||||
@Mappings(
|
||||
{
|
||||
@Mapping(source = "timeAndFormat", target = "time"),
|
||||
@Mapping(source = "timeAndFormat", target = "format")
|
||||
})
|
||||
Target sourceToTarget( Source s );
|
||||
{
|
||||
@Mapping(source = "timeAndFormat", target = "time"),
|
||||
@Mapping(source = "timeAndFormat", target = "format")
|
||||
})
|
||||
Target sourceToTarget(Source s);
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ package org.mapstruct.ap.test.severaltargets;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class Target {
|
||||
|
@ -21,7 +21,6 @@ package org.mapstruct.ap.test.severaltargets;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class TimeAndFormat {
|
||||
|
@ -21,7 +21,6 @@ package org.mapstruct.ap.test.severaltargets;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class TimeAndFormatMapper {
|
||||
|
Loading…
x
Reference in New Issue
Block a user