mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#275 do not register Java 8 Date/Time built-in methods if the types are not available
This commit is contained in:
parent
6093f525ed
commit
a979e4ec4a
@ -18,10 +18,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.mapstruct.ap.model.source.builtin;
|
package org.mapstruct.ap.model.source.builtin;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.mapstruct.ap.model.common.TypeFactory;
|
import org.mapstruct.ap.model.common.TypeFactory;
|
||||||
|
import org.mapstruct.ap.util.Collections;
|
||||||
|
import org.mapstruct.ap.util.JavaTimeConstants;
|
||||||
|
import org.mapstruct.ap.util.NativeTypes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registry for all built-in methods.
|
* Registry for all built-in methods.
|
||||||
@ -33,7 +35,7 @@ public class BuiltInMappingMethods {
|
|||||||
private final List<BuiltInMethod> builtInMethods;
|
private final List<BuiltInMethod> builtInMethods;
|
||||||
|
|
||||||
public BuiltInMappingMethods(TypeFactory typeFactory) {
|
public BuiltInMappingMethods(TypeFactory typeFactory) {
|
||||||
builtInMethods = Arrays.asList(
|
builtInMethods = Collections.newArrayList(
|
||||||
new JaxbElemToValue( typeFactory ),
|
new JaxbElemToValue( typeFactory ),
|
||||||
new ListOfJaxbElemToListOfValue( typeFactory ),
|
new ListOfJaxbElemToListOfValue( typeFactory ),
|
||||||
new DateToXmlGregorianCalendar( typeFactory ),
|
new DateToXmlGregorianCalendar( typeFactory ),
|
||||||
@ -41,11 +43,18 @@ public class BuiltInMappingMethods {
|
|||||||
new StringToXmlGregorianCalendar( typeFactory ),
|
new StringToXmlGregorianCalendar( typeFactory ),
|
||||||
new XmlGregorianCalendarToString( typeFactory ),
|
new XmlGregorianCalendarToString( typeFactory ),
|
||||||
new CalendarToXmlGregorianCalendar( typeFactory ),
|
new CalendarToXmlGregorianCalendar( typeFactory ),
|
||||||
new XmlGregorianCalendarToCalendar( typeFactory ),
|
new XmlGregorianCalendarToCalendar( typeFactory )
|
||||||
new ZonedDateTimeToCalendar( typeFactory ),
|
|
||||||
new CalendarToZonedDateTime( typeFactory )
|
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ( isJava8TimeAvailable() ) {
|
||||||
|
builtInMethods.add( new ZonedDateTimeToCalendar( typeFactory ) );
|
||||||
|
builtInMethods.add( new CalendarToZonedDateTime( typeFactory ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isJava8TimeAvailable() {
|
||||||
|
return NativeTypes.isTypeAvailable( JavaTimeConstants.ZONED_DATE_TIME_FQN );
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<BuiltInMethod> getBuiltInMethods() {
|
public List<BuiltInMethod> getBuiltInMethods() {
|
||||||
|
@ -18,8 +18,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.mapstruct.ap.util;
|
package org.mapstruct.ap.util;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,6 +45,14 @@ public class Collections {
|
|||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T> List<T> newArrayList(T... elements) {
|
||||||
|
List<T> list = new ArrayList<T>();
|
||||||
|
|
||||||
|
list.addAll( Arrays.asList( elements ) );
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
public static <T> Set<T> asSet(Collection<T> collection, T... elements) {
|
public static <T> Set<T> asSet(Collection<T> collection, T... elements) {
|
||||||
Set<T> set = new HashSet<T>( collection );
|
Set<T> set = new HashSet<T>( collection );
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user