mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#1050 Use the getNull method from the Type instead of the getDefaultValue
This commit is contained in:
parent
c9a313ac15
commit
56ea9dd168
@ -20,7 +20,6 @@ package org.mapstruct.ap.internal.model;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javax.lang.model.type.TypeKind;
|
|
||||||
|
|
||||||
import org.mapstruct.ap.internal.model.assignment.Assignment;
|
import org.mapstruct.ap.internal.model.assignment.Assignment;
|
||||||
import org.mapstruct.ap.internal.model.common.Parameter;
|
import org.mapstruct.ap.internal.model.common.Parameter;
|
||||||
@ -79,27 +78,6 @@ public abstract class ContainerMappingMethod extends NormalTypeMappingMethod {
|
|||||||
return loopVariableName;
|
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 abstract Type getResultElementType();
|
||||||
|
|
||||||
public String getIndex1Name() {
|
public String getIndex1Name() {
|
||||||
|
@ -758,10 +758,11 @@ public class Type extends ModelElement implements Comparable<Type> {
|
|||||||
return "0";
|
return "0";
|
||||||
}
|
}
|
||||||
if ( "char".equals( getName() ) ) {
|
if ( "char".equals( getName() ) ) {
|
||||||
return "'\\u0000'";
|
//"'\u0000'" would have been better, but depends on platform encoding
|
||||||
|
return "0";
|
||||||
}
|
}
|
||||||
if ( "double".equals( getName() ) ) {
|
if ( "double".equals( getName() ) ) {
|
||||||
return "0.0";
|
return "0.0d";
|
||||||
}
|
}
|
||||||
if ( "float".equals( getName() ) ) {
|
if ( "float".equals( getName() ) ) {
|
||||||
return "0.0f";
|
return "0.0f";
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
<#if existingInstanceMapping>
|
<#if existingInstanceMapping>
|
||||||
<#-- we can't clear an existing array, so we've got to clear by setting values to default -->
|
<#-- 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}++ ) {
|
for (int ${index2Name} = 0; ${index2Name} < ${resultName}.length; ${index2Name}++ ) {
|
||||||
${resultName}[${index2Name}] = ${defaultValue};
|
${resultName}[${index2Name}] = ${resultElementType.null};
|
||||||
}
|
}
|
||||||
return<#if returnType.name != "void"> ${resultName}</#if>;
|
return<#if returnType.name != "void"> ${resultName}</#if>;
|
||||||
<#else>
|
<#else>
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
<#if existingInstanceMapping>
|
<#if existingInstanceMapping>
|
||||||
<#-- we can't clear an existing array, so we've got to clear by setting values to default -->
|
<#-- 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}++ ) {
|
for (int ${index2Name} = 0; ${index2Name} < ${resultName}.length; ${index2Name}++ ) {
|
||||||
${resultName}[${index2Name}] = ${defaultValue};
|
${resultName}[${index2Name}] = ${resultElementType.null};
|
||||||
}
|
}
|
||||||
return<#if returnType.name != "void"> ${resultName}</#if>;
|
return<#if returnType.name != "void"> ${resultName}</#if>;
|
||||||
<#else>
|
<#else>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user