#92 Formatting and minor clean-ups

This commit is contained in:
Gunnar Morling 2014-01-20 23:20:41 +01:00
parent 6c2683a6f3
commit 8dd505b63e
7 changed files with 33 additions and 27 deletions

View File

@ -56,7 +56,7 @@ public class PropertyMapping extends AbstractModelElement {
this.targetName = targetName; this.targetName = targetName;
this.targetAccessorName = targetAccessorName; this.targetAccessorName = targetAccessorName;
this.targetType = targetType; this.targetType = targetType;
this.isHasTargetSetter = targetAccessorName.startsWith( "set" ); this.isHasTargetSetter = targetAccessorName.startsWith( "set" );
this.mappingMethod = mappingMethod; this.mappingMethod = mappingMethod;
this.conversion = conversion; this.conversion = conversion;

View File

@ -287,8 +287,10 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Metho
List<ExecutableElement> targetAccessors = filters.setterMethodsIn( List<ExecutableElement> targetAccessors = filters.setterMethodsIn(
elementUtils.getAllMembers( resultTypeElement ) elementUtils.getAllMembers( resultTypeElement )
); );
targetAccessors.addAll( filters.alternativeTargetAccessorMethodsIn( targetAccessors.addAll(
elementUtils.getAllMembers( resultTypeElement ) ) filters.alternativeTargetAccessorMethodsIn(
elementUtils.getAllMembers( resultTypeElement )
)
); );
for ( ExecutableElement targetAccessor : targetAccessors ) { for ( ExecutableElement targetAccessor : targetAccessors ) {
@ -386,8 +388,10 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Metho
List<ExecutableElement> targetAccessors = filters.setterMethodsIn( List<ExecutableElement> targetAccessors = filters.setterMethodsIn(
elementUtils.getAllMembers( parameterTypeElement ) elementUtils.getAllMembers( parameterTypeElement )
); );
targetAccessors.addAll( filters.alternativeTargetAccessorMethodsIn( targetAccessors.addAll(
elementUtils.getAllMembers( parameterTypeElement ) ) filters.alternativeTargetAccessorMethodsIn(
elementUtils.getAllMembers( parameterTypeElement )
)
); );
return executables.getPropertyNames( targetAccessors ).contains( propertyName ); return executables.getPropertyNames( targetAccessors ).contains( propertyName );
} }
@ -397,8 +401,10 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Metho
List<ExecutableElement> targetAccessors = filters.setterMethodsIn( List<ExecutableElement> targetAccessors = filters.setterMethodsIn(
elementUtils.getAllMembers( resultTypeElement ) elementUtils.getAllMembers( resultTypeElement )
); );
targetAccessors.addAll( filters.alternativeTargetAccessorMethodsIn( targetAccessors.addAll(
elementUtils.getAllMembers( resultTypeElement ) ) filters.alternativeTargetAccessorMethodsIn(
elementUtils.getAllMembers( resultTypeElement )
)
); );
Set<String> targetProperties = executables.getPropertyNames( targetAccessors ); Set<String> targetProperties = executables.getPropertyNames( targetAccessors );
@ -481,7 +487,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Metho
Type sourceType = executables.retrieveReturnType( getterMethod ); Type sourceType = executables.retrieveReturnType( getterMethod );
Type targetType = null; Type targetType = null;
String conversionStr = null; String conversionStr = null;
if (executables.isSetterMethod( setterMethod ) ) { if ( executables.isSetterMethod( setterMethod ) ) {
targetType = executables.retrieveSingleParameter( setterMethod ).getType(); targetType = executables.retrieveSingleParameter( setterMethod ).getType();
conversionStr = parameter.getName() + "." + getterMethod.getSimpleName().toString() + "()"; conversionStr = parameter.getName() + "." + getterMethod.getSimpleName().toString() + "()";
} }

View File

@ -68,6 +68,7 @@ public class Filters {
* Provided such a getter is initialized lazy by the target class, e.g. in generated JAXB beans. * Provided such a getter is initialized lazy by the target class, e.g. in generated JAXB beans.
* *
* @param elements * @param elements
*
* @return * @return
*/ */
public List<ExecutableElement> alternativeTargetAccessorMethodsIn(Iterable<? extends Element> elements) { public List<ExecutableElement> alternativeTargetAccessorMethodsIn(Iterable<? extends Element> elements) {
@ -75,10 +76,10 @@ public class Filters {
List<ExecutableElement> getterMethods = getterMethodsIn( elements ); List<ExecutableElement> getterMethods = getterMethodsIn( elements );
List<ExecutableElement> alternativeTargetAccessorsMethods = new LinkedList<ExecutableElement>(); List<ExecutableElement> alternativeTargetAccessorsMethods = new LinkedList<ExecutableElement>();
if (getterMethods.size() > setterMethods.size()) { if ( getterMethods.size() > setterMethods.size() ) {
// there could be a getter method for a list that is not present as setter. // there could be a getter method for a list that is not present as setter.
// a getter could substitue the setter in that case and act as setter. // a getter could substitute the setter in that case and act as setter.
// (asuming its intitialized) // (assuming it is initialized)
for ( ExecutableElement getterMethod : getterMethods ) { for ( ExecutableElement getterMethod : getterMethods ) {
boolean matchFound = false; boolean matchFound = false;
String getterPropertyName = executables.getPropertyName( getterMethod ); String getterPropertyName = executables.getPropertyName( getterMethod );

View File

@ -57,7 +57,6 @@ public class TypeFactory {
private final TypeMirror iterableType; private final TypeMirror iterableType;
private final TypeMirror collectionType; private final TypeMirror collectionType;
private final TypeMirror listType;
private final TypeMirror mapType; private final TypeMirror mapType;
private final Map<String, Type> implementationTypes = new HashMap<String, Type>(); private final Map<String, Type> implementationTypes = new HashMap<String, Type>();
@ -71,7 +70,6 @@ public class TypeFactory {
elementUtils.getTypeElement( Collection.class.getCanonicalName() ) elementUtils.getTypeElement( Collection.class.getCanonicalName() )
.asType() .asType()
); );
listType = typeUtils.erasure( elementUtils.getTypeElement( List.class.getCanonicalName() ).asType() );
mapType = typeUtils.erasure( elementUtils.getTypeElement( Map.class.getCanonicalName() ).asType() ); mapType = typeUtils.erasure( elementUtils.getTypeElement( Map.class.getCanonicalName() ).asType() );
implementationTypes.put( Iterable.class.getName(), getType( ArrayList.class ) ); implementationTypes.put( Iterable.class.getName(), getType( ArrayList.class ) );

View File

@ -131,7 +131,7 @@ public class Source {
return stringList2; return stringList2;
} }
public void setStringList2( List<String> stringList2 ) { public void setStringList2(List<String> stringList2) {
this.stringList2 = stringList2; this.stringList2 = stringList2;
} }

View File

@ -18,9 +18,6 @@
*/ */
package org.mapstruct.ap.test.collection.defaultimplementation; package org.mapstruct.ap.test.collection.defaultimplementation;
import static org.fest.assertions.Assertions.assertThat;
import static org.fest.assertions.MapAssert.entry;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@ -41,6 +38,9 @@ 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 static org.fest.assertions.MapAssert.entry;
@WithClasses({ @WithClasses({
Source.class, Source.class,
Target.class, Target.class,
@ -51,7 +51,7 @@ import org.testng.annotations.Test;
public class DefaultCollectionImplementationTest extends MapperTestBase { public class DefaultCollectionImplementationTest extends MapperTestBase {
@Test @Test
@IssueKey( "6" ) @IssueKey("6")
public void shouldUseDefaultImplementationForConcurrentMap() { public void shouldUseDefaultImplementationForConcurrentMap() {
ConcurrentMap<String, TargetFoo> target = ConcurrentMap<String, TargetFoo> target =
SourceTargetMapper.INSTANCE.sourceFooMapToTargetFooConcurrentMap( createSourceFooMap() ); SourceTargetMapper.INSTANCE.sourceFooMapToTargetFooConcurrentMap( createSourceFooMap() );
@ -60,7 +60,7 @@ public class DefaultCollectionImplementationTest extends MapperTestBase {
} }
@Test @Test
@IssueKey( "6" ) @IssueKey("6")
public void shouldUseDefaultImplementationForConcurrentNavigableMap() { public void shouldUseDefaultImplementationForConcurrentNavigableMap() {
ConcurrentNavigableMap<String, TargetFoo> target = ConcurrentNavigableMap<String, TargetFoo> target =
SourceTargetMapper.INSTANCE.sourceFooMapToTargetFooConcurrentNavigableMap( createSourceFooMap() ); SourceTargetMapper.INSTANCE.sourceFooMapToTargetFooConcurrentNavigableMap( createSourceFooMap() );
@ -69,7 +69,7 @@ public class DefaultCollectionImplementationTest extends MapperTestBase {
} }
@Test @Test
@IssueKey( "6" ) @IssueKey("6")
public void shouldUseDefaultImplementationForMap() { public void shouldUseDefaultImplementationForMap() {
Map<String, TargetFoo> target = SourceTargetMapper.INSTANCE.sourceFooMapToTargetFooMap( createSourceFooMap() ); Map<String, TargetFoo> target = SourceTargetMapper.INSTANCE.sourceFooMapToTargetFooMap( createSourceFooMap() );
@ -77,7 +77,7 @@ public class DefaultCollectionImplementationTest extends MapperTestBase {
} }
@Test @Test
@IssueKey( "6" ) @IssueKey("6")
public void shouldUseDefaultImplementationForNavigableMap() { public void shouldUseDefaultImplementationForNavigableMap() {
NavigableMap<String, TargetFoo> target = NavigableMap<String, TargetFoo> target =
SourceTargetMapper.INSTANCE.sourceFooMapToTargetFooNavigableMap( createSourceFooMap() ); SourceTargetMapper.INSTANCE.sourceFooMapToTargetFooNavigableMap( createSourceFooMap() );
@ -86,7 +86,7 @@ public class DefaultCollectionImplementationTest extends MapperTestBase {
} }
@Test @Test
@IssueKey( "6" ) @IssueKey("6")
public void shouldUseDefaultImplementationForSortedMap() { public void shouldUseDefaultImplementationForSortedMap() {
SortedMap<String, TargetFoo> target = SortedMap<String, TargetFoo> target =
SourceTargetMapper.INSTANCE.sourceFooMapToTargetFooSortedMap( createSourceFooMap() ); SourceTargetMapper.INSTANCE.sourceFooMapToTargetFooSortedMap( createSourceFooMap() );
@ -95,7 +95,7 @@ public class DefaultCollectionImplementationTest extends MapperTestBase {
} }
@Test @Test
@IssueKey( "6" ) @IssueKey("6")
public void shouldUseDefaultImplementationForNaviableSet() { public void shouldUseDefaultImplementationForNaviableSet() {
NavigableSet<TargetFoo> target = NavigableSet<TargetFoo> target =
SourceTargetMapper.INSTANCE.sourceFoosToTargetFooNavigableSet( createSourceFooList() ); SourceTargetMapper.INSTANCE.sourceFoosToTargetFooNavigableSet( createSourceFooList() );
@ -139,7 +139,7 @@ public class DefaultCollectionImplementationTest extends MapperTestBase {
} }
@Test @Test
@IssueKey( "6" ) @IssueKey("6")
public void shouldUseDefaultImplementationForSortedSet() { public void shouldUseDefaultImplementationForSortedSet() {
SortedSet<TargetFoo> target = SortedSet<TargetFoo> target =
SourceTargetMapper.INSTANCE.sourceFoosToTargetFooSortedSet( createSourceFooList() ); SourceTargetMapper.INSTANCE.sourceFoosToTargetFooSortedSet( createSourceFooList() );
@ -153,7 +153,8 @@ public class DefaultCollectionImplementationTest extends MapperTestBase {
List<TargetFoo> target = new ArrayList<TargetFoo>(); List<TargetFoo> target = new ArrayList<TargetFoo>();
SourceTargetMapper.INSTANCE.sourceFoosToTargetFoosUsingTargetParameter( SourceTargetMapper.INSTANCE.sourceFoosToTargetFoosUsingTargetParameter(
target, target,
createSourceFooList() ); createSourceFooList()
);
assertResultList( target ); assertResultList( target );
} }
@ -178,7 +179,7 @@ public class DefaultCollectionImplementationTest extends MapperTestBase {
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
assertThat( target ).isNotNull(); assertThat( target ).isNotNull();
assertThat( target.getFooListNoSetter()).containsExactly( new TargetFoo( "Bob" ), new TargetFoo( "Alice" ) ); assertThat( target.getFooListNoSetter() ).containsExactly( new TargetFoo( "Bob" ), new TargetFoo( "Alice" ) );
} }
private void assertResultList(Iterable<TargetFoo> fooIterable) { private void assertResultList(Iterable<TargetFoo> fooIterable) {

View File

@ -28,7 +28,7 @@ public class Source {
return fooList; return fooList;
} }
public void setFooList( List<SourceFoo> fooList ) { public void setFooList(List<SourceFoo> fooList) {
this.fooList = fooList; this.fooList = fooList;
} }