diff --git a/processor/src/main/java/org/mapstruct/ap/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/model/MapMappingMethod.java index 586e04c28..6086cbbab 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/model/MapMappingMethod.java @@ -65,8 +65,13 @@ public class MapMappingMethod extends MappingMethod { @Override public Set getImportTypes() { Set types = super.getImportTypes(); - types.addAll( valueConversion.getImportTypes() ); - types.addAll( keyConversion.getImportTypes() ); + + if ( valueConversion != null ) { + types.addAll( valueConversion.getImportTypes() ); + } + if ( keyConversion != null ) { + types.addAll( keyConversion.getImportTypes() ); + } return types; } diff --git a/processor/src/main/java/org/mapstruct/ap/model/Type.java b/processor/src/main/java/org/mapstruct/ap/model/Type.java index b0c2ccb13..1aaeee9a9 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/model/Type.java @@ -26,9 +26,17 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.NavigableMap; +import java.util.NavigableSet; import java.util.Set; +import java.util.SortedMap; +import java.util.SortedSet; +import java.util.TreeMap; +import java.util.TreeSet; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ConcurrentNavigableMap; +import java.util.concurrent.ConcurrentSkipListMap; import org.mapstruct.ap.util.Strings; @@ -55,20 +63,32 @@ public class Type extends AbstractModelElement implements Comparable { new ConcurrentHashMap(); static { - DEFAULT_COLLECTION_IMPLEMENTATION_TYPES.put( List.class.getName(), forClass( ArrayList.class ) ); - DEFAULT_COLLECTION_IMPLEMENTATION_TYPES.put( Set.class.getName(), forClass( HashSet.class ) ); + DEFAULT_ITERABLE_IMPLEMENTATION_TYPES.put( Iterable.class.getName(), forClass( ArrayList.class ) ); DEFAULT_COLLECTION_IMPLEMENTATION_TYPES.put( Collection.class.getName(), forClass( ArrayList.class ) ); - DEFAULT_ITERABLE_IMPLEMENTATION_TYPES.put( Iterable.class.getName(), forClass( ArrayList.class ) ); + DEFAULT_COLLECTION_IMPLEMENTATION_TYPES.put( List.class.getName(), forClass( ArrayList.class ) ); + + DEFAULT_COLLECTION_IMPLEMENTATION_TYPES.put( Set.class.getName(), forClass( HashSet.class ) ); + DEFAULT_COLLECTION_IMPLEMENTATION_TYPES.put( SortedSet.class.getName(), forClass( TreeSet.class ) ); + DEFAULT_COLLECTION_IMPLEMENTATION_TYPES.put( NavigableSet.class.getName(), forClass( TreeSet.class ) ); + DEFAULT_ITERABLE_IMPLEMENTATION_TYPES.putAll( DEFAULT_COLLECTION_IMPLEMENTATION_TYPES ); DEFAULT_MAP_IMPLEMENTATION_TYPES.put( Map.class.getName(), forClass( HashMap.class ) ); + DEFAULT_MAP_IMPLEMENTATION_TYPES.put( SortedMap.class.getName(), forClass( TreeMap.class ) ); + DEFAULT_MAP_IMPLEMENTATION_TYPES.put( NavigableMap.class.getName(), forClass( TreeMap.class ) ); + DEFAULT_MAP_IMPLEMENTATION_TYPES.put( ConcurrentMap.class.getName(), forClass( ConcurrentHashMap.class ) ); + DEFAULT_MAP_IMPLEMENTATION_TYPES.put( + ConcurrentNavigableMap.class.getName(), + forClass( ConcurrentSkipListMap.class ) + ); } private final String canonicalName; private final String packageName; private final String name; private final List typeParameters; + private final boolean isInterface; private final boolean isEnumType; private final boolean isCollectionType; private final boolean isIterableType; @@ -85,6 +105,7 @@ public class Type extends AbstractModelElement implements Comparable { clazz.getCanonicalName(), pakkage.getName(), clazz.getSimpleName(), + clazz.isInterface(), clazz.isEnum(), Collection.class.isAssignableFrom( clazz ), Iterable.class.isAssignableFrom( clazz ), @@ -98,18 +119,30 @@ public class Type extends AbstractModelElement implements Comparable { } public Type(String name) { - this( name, null, name, false, false, false, false, Collections.emptyList() ); + this( name, null, name, false, false, false, false, false, Collections.emptyList() ); } public Type(String packageName, String name) { - this( packageName + "." + name, packageName, name, false, false, false, false, Collections.emptyList() ); + this( + packageName + "." + name, + packageName, + name, + false, + false, + false, + false, + false, + Collections.emptyList() + ); } - public Type(String canonicalName, String packageName, String name, boolean isEnumType, boolean isCollectionType, + public Type(String canonicalName, String packageName, String name, boolean isInterface, boolean isEnumType, + boolean isCollectionType, boolean isIterableType, boolean isMapType, List typeParameters) { this.canonicalName = canonicalName; this.packageName = packageName; this.name = name; + this.isInterface = isInterface; this.isEnumType = isEnumType; this.isCollectionType = isCollectionType; this.isIterableType = isIterableType; @@ -136,6 +169,7 @@ public class Type extends AbstractModelElement implements Comparable { mapType.getPackageName() + "." + mapType.getName(), mapType.getPackageName(), mapType.getName(), + mapType.isInterface(), mapType.isEnumType(), mapType.isCollectionType(), mapType.isIterableType(), @@ -168,6 +202,10 @@ public class Type extends AbstractModelElement implements Comparable { return packageName == null && PRIMITIVE_TYPE_NAMES.contains( name ); } + public boolean isInterface() { + return isInterface; + } + public boolean isEnumType() { return isEnumType; } @@ -188,6 +226,12 @@ public class Type extends AbstractModelElement implements Comparable { return isCollectionType; } + public Type getImplementationType() { + return collectionImplementationType != null ? collectionImplementationType : + iterableImplementationType != null ? iterableImplementationType : + mapImplementationType; + } + public boolean isIterableType() { return isIterableType; } diff --git a/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java index dfa96d73f..4883b8c9c 100644 --- a/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java @@ -157,6 +157,8 @@ public class MapperCreationProcessor implements ModelElementProcessor reverse(Map mappings) { Map reversed = new HashMap(); diff --git a/processor/src/main/java/org/mapstruct/ap/util/TypeUtil.java b/processor/src/main/java/org/mapstruct/ap/util/TypeUtil.java index 3d3b072d7..734c0c40a 100644 --- a/processor/src/main/java/org/mapstruct/ap/util/TypeUtil.java +++ b/processor/src/main/java/org/mapstruct/ap/util/TypeUtil.java @@ -60,6 +60,7 @@ public class TypeUtil { ( (TypeElement) type.asElement() ).getQualifiedName().toString(), elementUtils.getPackageOf( type.asElement() ).toString(), type.asElement().getSimpleName().toString(), + type.asElement().getKind() == ElementKind.INTERFACE, type.asElement().getKind() == ElementKind.ENUM, isCollectionType( type ), isIterableType,