#306 IllegalArgumentException due to void type parameter

This commit is contained in:
sjaakd 2014-10-01 21:28:41 +02:00 committed by Gunnar Morling
parent e9a74d1fc0
commit 3342990387
4 changed files with 30 additions and 6 deletions

View File

@ -32,6 +32,7 @@ import javax.lang.model.element.Modifier;
import javax.lang.model.element.Name;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Elements;
import javax.lang.model.util.Types;
@ -72,6 +73,8 @@ public class Type extends ModelElement implements Comparable<Type> {
private final boolean isCollectionType;
private final boolean isMapType;
private final boolean isImported;
private final boolean isVoid;
private final List<String> enumConstants;
private List<ExecutableElement> getters = null;
@ -103,6 +106,7 @@ public class Type extends ModelElement implements Comparable<Type> {
this.isCollectionType = isCollectionType;
this.isMapType = isMapType;
this.isImported = isImported;
this.isVoid = typeMirror.getKind().equals( TypeKind.VOID );
if ( isEnumType ) {
enumConstants = new ArrayList<String>();
@ -154,6 +158,10 @@ public class Type extends ModelElement implements Comparable<Type> {
return isEnumType;
}
public boolean isVoid() {
return isVoid;
}
/**
* Returns this type's enum constants in case it is an enum, an empty list otherwise.
*/

View File

@ -193,7 +193,10 @@ public class TypeFactory {
*/
public Type classTypeOf(Type type) {
TypeMirror typeToUse;
if ( type.isPrimitive() ) {
if ( type.isVoid() ) {
return null;
}
else if ( type.isPrimitive() ) {
typeToUse = typeUtils.boxedClass( (PrimitiveType) type.getTypeMirror() ).asType();
}
else {

View File

@ -18,14 +18,27 @@
*/
package org.mapstruct.ap.test.collection.forged;
import java.util.Set;
import org.mapstruct.Mapper;
import org.mapstruct.TargetType;
import org.mapstruct.factory.Mappers;
@Mapper
public interface CollectionMapper {
public abstract class CollectionMapper {
CollectionMapper INSTANCE = Mappers.getMapper( CollectionMapper.class );
public static final CollectionMapper INSTANCE = Mappers.getMapper( CollectionMapper.class );
Target sourceToTarget(Source source);
Source targetToSource(Target target);
public abstract Target sourceToTarget(Source source);
public abstract Source targetToSource(Target target);
// this method is added to reproduce issue 306
protected void dummy1( Set<String> arg ) {
throw new RuntimeException();
}
// this method is added to reproduce issue 306
protected Set<Long> dummy2( Object object, @TargetType Class clazz ) {
throw new RuntimeException();
}
}

View File

@ -34,7 +34,7 @@ import org.mapstruct.ap.util.Collections;
*
* @author Sjaak Derksen
*/
@IssueKey("4")
@IssueKey("4, 306")
@RunWith(AnnotationProcessorTestRunner.class)
public class CollectionMappingTest {