mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#853 Minor adjustments after review
This commit is contained in:
parent
1be3c4dbaa
commit
f822000f92
@ -253,7 +253,7 @@ public class IterableMappingMethod extends MappingMethod {
|
|||||||
return sourceParameterType.getComponentType();
|
return sourceParameterType.getComponentType();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return sourceParameterType.determineTypeArguments( Iterable.class ).get( 0 ).getTypeBound();
|
return first( sourceParameterType.determineTypeArguments( Iterable.class ) ).getTypeBound();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,7 +262,7 @@ public class IterableMappingMethod extends MappingMethod {
|
|||||||
return getResultType().getComponentType();
|
return getResultType().getComponentType();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return getResultType().determineTypeArguments( Iterable.class ).get( 0 );
|
return first( getResultType().determineTypeArguments( Iterable.class ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -798,10 +798,7 @@ public class Type extends ModelElement implements Comparable<Type> {
|
|||||||
* @return a list of type arguments or null, if superclass was not found
|
* @return a list of type arguments or null, if superclass was not found
|
||||||
*/
|
*/
|
||||||
public List<Type> determineTypeArguments(Class<?> superclass) {
|
public List<Type> determineTypeArguments(Class<?> superclass) {
|
||||||
TypeMirror superclassMirror =
|
if ( qualifiedName.equals( superclass.getName() ) ) {
|
||||||
typeUtils.erasure( elementUtils.getTypeElement( superclass.getCanonicalName() ).asType() );
|
|
||||||
if ( typeUtils.isAssignable( superclassMirror, typeMirror )
|
|
||||||
&& typeUtils.isAssignable( typeMirror, superclassMirror ) ) {
|
|
||||||
return getTypeParameters();
|
return getTypeParameters();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
package org.mapstruct.ap.test.collection;
|
package org.mapstruct.ap.test.collection;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.entry;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -29,7 +30,6 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.fest.assertions.MapAssert;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mapstruct.ap.testutil.IssueKey;
|
import org.mapstruct.ap.testutil.IssueKey;
|
||||||
@ -37,7 +37,7 @@ import org.mapstruct.ap.testutil.WithClasses;
|
|||||||
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
|
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
|
||||||
|
|
||||||
@WithClasses({ Source.class, Target.class, Colour.class, SourceTargetMapper.class, TestList.class, TestMap.class,
|
@WithClasses({ Source.class, Target.class, Colour.class, SourceTargetMapper.class, TestList.class, TestMap.class,
|
||||||
TestNonGenericList.class, StringToLongMap.class })
|
StringArrayList.class, StringToLongMap.class })
|
||||||
@RunWith(AnnotationProcessorTestRunner.class)
|
@RunWith(AnnotationProcessorTestRunner.class)
|
||||||
public class CollectionMappingTest {
|
public class CollectionMappingTest {
|
||||||
|
|
||||||
@ -393,7 +393,7 @@ public class CollectionMappingTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@IssueKey("TODO")
|
@IssueKey("853")
|
||||||
public void shouldMapNonGenericList() {
|
public void shouldMapNonGenericList() {
|
||||||
Source source = new Source();
|
Source source = new Source();
|
||||||
source.setStringList3( new ArrayList<String>( Arrays.asList( "Bob", "Alice" ) ) );
|
source.setStringList3( new ArrayList<String>( Arrays.asList( "Bob", "Alice" ) ) );
|
||||||
@ -405,7 +405,7 @@ public class CollectionMappingTest {
|
|||||||
|
|
||||||
// Inverse direction
|
// Inverse direction
|
||||||
Target newTarget = new Target();
|
Target newTarget = new Target();
|
||||||
TestNonGenericList nonGenericStringList = new TestNonGenericList();
|
StringArrayList nonGenericStringList = new StringArrayList();
|
||||||
nonGenericStringList.addAll( Arrays.asList( "Bill", "Bob" ) );
|
nonGenericStringList.addAll( Arrays.asList( "Bill", "Bob" ) );
|
||||||
newTarget.setNonGenericStringList( nonGenericStringList );
|
newTarget.setNonGenericStringList( nonGenericStringList );
|
||||||
|
|
||||||
@ -416,7 +416,7 @@ public class CollectionMappingTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@IssueKey("TODO")
|
@IssueKey("853")
|
||||||
public void shouldMapNonGenericMap() {
|
public void shouldMapNonGenericMap() {
|
||||||
Source source = new Source();
|
Source source = new Source();
|
||||||
Map<String, Long> map = new HashMap<String, Long>();
|
Map<String, Long> map = new HashMap<String, Long>();
|
||||||
@ -427,8 +427,7 @@ public class CollectionMappingTest {
|
|||||||
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
|
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
|
||||||
|
|
||||||
assertThat( target ).isNotNull();
|
assertThat( target ).isNotNull();
|
||||||
assertThat( target.getNonGenericMapStringtoLong() ).includes( MapAssert.entry( "Bob", 123L ),
|
assertThat( target.getNonGenericMapStringtoLong() ).contains( entry( "Bob", 123L ), entry( "Alice", 456L ) );
|
||||||
MapAssert.entry( "Alice", 456L ) );
|
|
||||||
|
|
||||||
// Inverse direction
|
// Inverse direction
|
||||||
Target newTarget = new Target();
|
Target newTarget = new Target();
|
||||||
@ -440,7 +439,8 @@ public class CollectionMappingTest {
|
|||||||
Source mappedSource = SourceTargetMapper.INSTANCE.targetToSource( newTarget );
|
Source mappedSource = SourceTargetMapper.INSTANCE.targetToSource( newTarget );
|
||||||
|
|
||||||
assertThat( mappedSource ).isNotNull();
|
assertThat( mappedSource ).isNotNull();
|
||||||
assertThat( mappedSource.getStringLongMapForNonGeneric() ).includes( MapAssert.entry( "Blue", 321L ),
|
assertThat( mappedSource.getStringLongMapForNonGeneric() ).contains(
|
||||||
MapAssert.entry( "Green", 654L ) );
|
entry( "Blue", 321L ),
|
||||||
|
entry( "Green", 654L ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ import java.util.ArrayList;
|
|||||||
/**
|
/**
|
||||||
* @author Stefan May
|
* @author Stefan May
|
||||||
*/
|
*/
|
||||||
public class TestNonGenericList extends ArrayList<String> {
|
public class StringArrayList extends ArrayList<String> {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
}
|
}
|
@ -58,7 +58,7 @@ public class Target {
|
|||||||
|
|
||||||
private EnumSet<Colour> enumSet;
|
private EnumSet<Colour> enumSet;
|
||||||
|
|
||||||
private TestNonGenericList nonGenericStringList;
|
private StringArrayList nonGenericStringList;
|
||||||
|
|
||||||
private StringToLongMap nonGenericMapStringtoLong;
|
private StringToLongMap nonGenericMapStringtoLong;
|
||||||
|
|
||||||
@ -189,11 +189,11 @@ public class Target {
|
|||||||
this.enumSet = enumSet;
|
this.enumSet = enumSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TestNonGenericList getNonGenericStringList() {
|
public StringArrayList getNonGenericStringList() {
|
||||||
return nonGenericStringList;
|
return nonGenericStringList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNonGenericStringList(TestNonGenericList nonGenericStringList) {
|
public void setNonGenericStringList(StringArrayList nonGenericStringList) {
|
||||||
this.nonGenericStringList = nonGenericStringList;
|
this.nonGenericStringList = nonGenericStringList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user