#1050 Use the getNull method from the Type instead of the getDefaultValue

This commit is contained in:
Filip Hrisafov 2017-02-04 10:16:55 +01:00
parent c9a313ac15
commit 56ea9dd168
4 changed files with 5 additions and 26 deletions

View File

@ -20,7 +20,6 @@ package org.mapstruct.ap.internal.model;
import java.util.List;
import java.util.Set;
import javax.lang.model.type.TypeKind;
import org.mapstruct.ap.internal.model.assignment.Assignment;
import org.mapstruct.ap.internal.model.common.Parameter;
@ -79,27 +78,6 @@ public abstract class ContainerMappingMethod extends NormalTypeMappingMethod {
return loopVariableName;
}
public String getDefaultValue() {
TypeKind kind = getResultElementType().getTypeMirror().getKind();
switch ( kind ) {
case BOOLEAN:
return "false";
case BYTE:
case SHORT:
case INT:
case CHAR: /*"'\u0000'" would have been better, but depends on platformencoding */
return "0";
case LONG:
return "0L";
case FLOAT:
return "0.0f";
case DOUBLE:
return "0.0d";
default:
return "null";
}
}
public abstract Type getResultElementType();
public String getIndex1Name() {

View File

@ -758,10 +758,11 @@ public class Type extends ModelElement implements Comparable<Type> {
return "0";
}
if ( "char".equals( getName() ) ) {
return "'\\u0000'";
//"'\u0000'" would have been better, but depends on platform encoding
return "0";
}
if ( "double".equals( getName() ) ) {
return "0.0";
return "0.0d";
}
if ( "float".equals( getName() ) ) {
return "0.0f";

View File

@ -35,7 +35,7 @@
<#if existingInstanceMapping>
<#-- we can't clear an existing array, so we've got to clear by setting values to default -->
for (int ${index2Name} = 0; ${index2Name} < ${resultName}.length; ${index2Name}++ ) {
${resultName}[${index2Name}] = ${defaultValue};
${resultName}[${index2Name}] = ${resultElementType.null};
}
return<#if returnType.name != "void"> ${resultName}</#if>;
<#else>

View File

@ -37,7 +37,7 @@
<#if existingInstanceMapping>
<#-- we can't clear an existing array, so we've got to clear by setting values to default -->
for (int ${index2Name} = 0; ${index2Name} < ${resultName}.length; ${index2Name}++ ) {
${resultName}[${index2Name}] = ${defaultValue};
${resultName}[${index2Name}] = ${resultElementType.null};
}
return<#if returnType.name != "void"> ${resultName}</#if>;
<#else>