+ * The first time a name is referred-to it will be marked as to be imported. For instance + * {@code LocalDateTime} can be one of {@code java.time.LocalDateTime} and {@code org.joda.LocalDateTime}) + *
+ * If the {@code java.time} variant is referred to first, the {@code java.time.LocalDateTime} will be imported
+ * and the {@code org.joda} variant will be referred to with its FQN.
*
* @return Just the name if this {@link Type} will be imported, otherwise the fully-qualified name.
*/
- public String getReferenceName() {
- return isImported ? name : qualifiedName;
+ public String createReferenceName() {
+ return isToBeImported() ? name : ( shouldUseSimpleName() ? name : qualifiedName );
}
public List
+ * trimSimpleClassName("String[][][]") -> "String"
+ * trimSimpleClassName("String[]") -> "String"
+ *
+ *
+ * @param className that needs to be trimmed
+ *
+ * @return the trimmed {@code className}, or {@code null} if the {@code className} was {@code null}
+ */
+ private String trimSimpleClassName(String className) {
+ if ( className == null ) {
+ return null;
+ }
+ String trimmedClassName = className;
+ while ( trimmedClassName.endsWith( "[]" ) ) {
+ trimmedClassName = trimmedClassName.substring( 0, trimmedClassName.length() - 2 );
+ }
+ return trimmedClassName;
+ }
+
}
diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java
index 6f46f073e..567053986 100644
--- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java
+++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java
@@ -84,13 +84,16 @@ public class TypeFactory {
private final TypeMirror streamType;
private final Map
- * trimSimpleClassName("String[][][]") -> "String"
- * trimSimpleClassName("String[]") -> "String"
- *
- *
- * @param className that needs to be trimmed
- *
- * @return the trimmed {@code className}, or {@code null} if the {@code className} was {@code null}
- */
- static String trimSimpleClassName(String className) {
- if ( className == null ) {
- return null;
- }
- String trimmedClassName = className;
- while ( trimmedClassName.endsWith( "[]" ) ) {
- trimmedClassName = trimmedClassName.substring( 0, trimmedClassName.length() - 2 );
- }
- return trimmedClassName;
- }
/**
* Whether the given type is ready to be processed or not. It can be processed if it is not of kind
diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java
index 908b8284f..5332651ab 100644
--- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java
+++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java
@@ -9,7 +9,6 @@ import java.util.ArrayList;
import java.util.List;
import org.mapstruct.ap.internal.model.common.TypeFactory;
-import org.mapstruct.ap.internal.util.JavaTimeConstants;
import org.mapstruct.ap.internal.util.JaxbConstants;
import org.mapstruct.ap.internal.util.JodaTimeConstants;
import org.mapstruct.ap.internal.util.XmlConstants;
@@ -33,21 +32,18 @@ public class BuiltInMappingMethods {
builtInMethods.add( new XmlGregorianCalendarToString( typeFactory ) );
builtInMethods.add( new CalendarToXmlGregorianCalendar( typeFactory ) );
builtInMethods.add( new XmlGregorianCalendarToCalendar( typeFactory ) );
+ builtInMethods.add( new ZonedDateTimeToXmlGregorianCalendar( typeFactory ) );
}
if ( isJaxbAvailable( typeFactory ) ) {
builtInMethods.add( new JaxbElemToValue( typeFactory ) );
}
-
- if ( isJava8TimeAvailable( typeFactory ) ) {
- builtInMethods.add( new ZonedDateTimeToCalendar( typeFactory ) );
- builtInMethods.add( new ZonedDateTimeToXmlGregorianCalendar( typeFactory ) );
- builtInMethods.add( new CalendarToZonedDateTime( typeFactory ) );
- if ( isXmlGregorianCalendarPresent ) {
- builtInMethods.add( new XmlGregorianCalendarToLocalDate( typeFactory ) );
- builtInMethods.add( new LocalDateToXmlGregorianCalendar( typeFactory ) );
- }
+ builtInMethods.add( new ZonedDateTimeToCalendar( typeFactory ) );
+ builtInMethods.add( new CalendarToZonedDateTime( typeFactory ) );
+ if ( isXmlGregorianCalendarPresent ) {
+ builtInMethods.add( new XmlGregorianCalendarToLocalDate( typeFactory ) );
+ builtInMethods.add( new LocalDateToXmlGregorianCalendar( typeFactory ) );
}
if ( isJodaTimeAvailable( typeFactory ) && isXmlGregorianCalendarPresent ) {
@@ -66,10 +62,6 @@ public class BuiltInMappingMethods {
return JaxbConstants.isJaxbElementPresent() && typeFactory.isTypeAvailable( JaxbConstants.JAXB_ELEMENT_FQN );
}
- private static boolean isJava8TimeAvailable(TypeFactory typeFactory) {
- return typeFactory.isTypeAvailable( JavaTimeConstants.ZONED_DATE_TIME_FQN );
- }
-
private static boolean isXmlGregorianCalendarAvailable(TypeFactory typeFactory) {
return XmlConstants.isXmlGregorianCalendarPresent() &&
typeFactory.isTypeAvailable( XmlConstants.JAVAX_XML_DATATYPE_XMLGREGORIAN_CALENDAR );
diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.java
index 478f03ee4..729b65e5e 100644
--- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.java
+++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.java
@@ -12,7 +12,6 @@ import java.util.Set;
import org.mapstruct.ap.internal.model.common.Parameter;
import org.mapstruct.ap.internal.model.common.Type;
import org.mapstruct.ap.internal.model.common.TypeFactory;
-import org.mapstruct.ap.internal.util.JavaTimeConstants;
import static org.mapstruct.ap.internal.util.Collections.asSet;
@@ -28,7 +27,7 @@ public class CalendarToZonedDateTime extends BuiltInMethod {
private final Set