mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#120 Don't hold a reference to TypeFactory in built-in method types
This commit is contained in:
parent
52ccedb0e1
commit
2398d94752
@ -35,6 +35,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
import java.util.concurrent.ConcurrentNavigableMap;
|
import java.util.concurrent.ConcurrentNavigableMap;
|
||||||
import java.util.concurrent.ConcurrentSkipListMap;
|
import java.util.concurrent.ConcurrentSkipListMap;
|
||||||
|
|
||||||
import javax.lang.model.element.ElementKind;
|
import javax.lang.model.element.ElementKind;
|
||||||
import javax.lang.model.element.ExecutableElement;
|
import javax.lang.model.element.ExecutableElement;
|
||||||
import javax.lang.model.element.TypeElement;
|
import javax.lang.model.element.TypeElement;
|
||||||
@ -201,15 +202,6 @@ public class TypeFactory {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Parameter createParameter(String name, Class<?> type) {
|
|
||||||
|
|
||||||
return new Parameter(
|
|
||||||
name,
|
|
||||||
getType( type )
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public List<Parameter> getParameters(ExecutableElement method) {
|
public List<Parameter> getParameters(ExecutableElement method) {
|
||||||
List<? extends VariableElement> parameters = method.getParameters();
|
List<? extends VariableElement> parameters = method.getParameters();
|
||||||
List<Parameter> result = new ArrayList<Parameter>( parameters.size() );
|
List<Parameter> result = new ArrayList<Parameter>( parameters.size() );
|
||||||
|
@ -21,7 +21,6 @@ package org.mapstruct.ap.model.source.builtin;
|
|||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.xml.datatype.DatatypeConfigurationException;
|
import javax.xml.datatype.DatatypeConfigurationException;
|
||||||
import javax.xml.datatype.DatatypeFactory;
|
import javax.xml.datatype.DatatypeFactory;
|
||||||
import javax.xml.datatype.XMLGregorianCalendar;
|
import javax.xml.datatype.XMLGregorianCalendar;
|
||||||
@ -33,27 +32,28 @@ import org.mapstruct.ap.model.common.TypeFactory;
|
|||||||
import static org.mapstruct.ap.util.Collections.asSet;
|
import static org.mapstruct.ap.util.Collections.asSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Sjaak Derksen
|
* @author Sjaak Derksen
|
||||||
*/
|
*/
|
||||||
public class CalendarToXmlGregorianCalendar extends BuiltInMethod {
|
public class CalendarToXmlGregorianCalendar extends BuiltInMethod {
|
||||||
|
|
||||||
private final Parameter parameter;
|
private final Parameter parameter;
|
||||||
private final Type returnType;
|
private final Type returnType;
|
||||||
|
private final Set<Type> importTypes;
|
||||||
|
|
||||||
private final TypeFactory typeFactory;
|
public CalendarToXmlGregorianCalendar(TypeFactory typeFactory) {
|
||||||
|
this.parameter = new Parameter( "cal ", typeFactory.getType( Calendar.class ) );
|
||||||
public CalendarToXmlGregorianCalendar( TypeFactory typeFactory ) {
|
|
||||||
this.typeFactory = typeFactory;
|
|
||||||
this.parameter = typeFactory.createParameter( "cal ", Calendar.class );
|
|
||||||
this.returnType = typeFactory.getType( XMLGregorianCalendar.class );
|
this.returnType = typeFactory.getType( XMLGregorianCalendar.class );
|
||||||
|
|
||||||
|
this.importTypes = asSet(
|
||||||
|
typeFactory.getType( DatatypeFactory.class ),
|
||||||
|
typeFactory.getType( GregorianCalendar.class ),
|
||||||
|
typeFactory.getType( DatatypeConfigurationException.class )
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Type> getImportTypes() {
|
public Set<Type> getImportTypes() {
|
||||||
return asSet( new Type[]{ typeFactory.getType( DatatypeFactory.class ),
|
return importTypes;
|
||||||
typeFactory.getType( GregorianCalendar.class ),
|
|
||||||
typeFactory.getType( DatatypeConfigurationException.class ) } );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -21,7 +21,6 @@ package org.mapstruct.ap.model.source.builtin;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.xml.datatype.DatatypeConfigurationException;
|
import javax.xml.datatype.DatatypeConfigurationException;
|
||||||
import javax.xml.datatype.DatatypeFactory;
|
import javax.xml.datatype.DatatypeFactory;
|
||||||
import javax.xml.datatype.XMLGregorianCalendar;
|
import javax.xml.datatype.XMLGregorianCalendar;
|
||||||
@ -33,27 +32,28 @@ import org.mapstruct.ap.model.common.TypeFactory;
|
|||||||
import static org.mapstruct.ap.util.Collections.asSet;
|
import static org.mapstruct.ap.util.Collections.asSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Sjaak Derksen
|
* @author Sjaak Derksen
|
||||||
*/
|
*/
|
||||||
public class DateToXmlGregorianCalendar extends BuiltInMethod {
|
public class DateToXmlGregorianCalendar extends BuiltInMethod {
|
||||||
|
|
||||||
private final Parameter parameter;
|
private final Parameter parameter;
|
||||||
private final Type returnType;
|
private final Type returnType;
|
||||||
|
private final Set<Type> importTypes;
|
||||||
|
|
||||||
private final TypeFactory typeFactory;
|
public DateToXmlGregorianCalendar(TypeFactory typeFactory) {
|
||||||
|
this.parameter = new Parameter( "date", typeFactory.getType( Date.class ) );
|
||||||
public DateToXmlGregorianCalendar( TypeFactory typeFactory ) {
|
|
||||||
this.typeFactory = typeFactory;
|
|
||||||
this.parameter = typeFactory.createParameter( "date", Date.class );
|
|
||||||
this.returnType = typeFactory.getType( XMLGregorianCalendar.class );
|
this.returnType = typeFactory.getType( XMLGregorianCalendar.class );
|
||||||
|
|
||||||
|
this.importTypes = asSet(
|
||||||
|
typeFactory.getType( GregorianCalendar.class ),
|
||||||
|
typeFactory.getType( DatatypeFactory.class ),
|
||||||
|
typeFactory.getType( DatatypeConfigurationException.class )
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Type> getImportTypes() {
|
public Set<Type> getImportTypes() {
|
||||||
return asSet( new Type[]{ typeFactory.getType( GregorianCalendar.class ),
|
return importTypes;
|
||||||
typeFactory.getType( DatatypeFactory.class ),
|
|
||||||
typeFactory.getType( DatatypeConfigurationException.class ) });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,7 +25,6 @@ import org.mapstruct.ap.model.common.Type;
|
|||||||
import org.mapstruct.ap.model.common.TypeFactory;
|
import org.mapstruct.ap.model.common.TypeFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Sjaak Derksen
|
* @author Sjaak Derksen
|
||||||
*/
|
*/
|
||||||
public class JaxbElemToValue extends BuiltInMethod {
|
public class JaxbElemToValue extends BuiltInMethod {
|
||||||
@ -33,15 +32,15 @@ public class JaxbElemToValue extends BuiltInMethod {
|
|||||||
private final Parameter parameter;
|
private final Parameter parameter;
|
||||||
private final Type returnType;
|
private final Type returnType;
|
||||||
|
|
||||||
public JaxbElemToValue( TypeFactory typeFactory ) {
|
public JaxbElemToValue(TypeFactory typeFactory) {
|
||||||
this.parameter = typeFactory.createParameter( "element", JAXBElement.class );
|
this.parameter = new Parameter( "element", typeFactory.getType( JAXBElement.class ) );
|
||||||
this.returnType = typeFactory.getType( Object.class );
|
this.returnType = typeFactory.getType( Object.class );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doTypeVarsMatch(Type sourceType, Type targetType) {
|
public boolean doTypeVarsMatch(Type sourceType, Type targetType) {
|
||||||
boolean match = false;
|
boolean match = false;
|
||||||
if (sourceType.getTypeParameters().size() == 1) {
|
if ( sourceType.getTypeParameters().size() == 1 ) {
|
||||||
match = sourceType.getTypeParameters().get( 0 ).equals( targetType );
|
match = sourceType.getTypeParameters().get( 0 ).equals( targetType );
|
||||||
}
|
}
|
||||||
return match;
|
return match;
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
package org.mapstruct.ap.model.source.builtin;
|
package org.mapstruct.ap.model.source.builtin;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.xml.bind.JAXBElement;
|
import javax.xml.bind.JAXBElement;
|
||||||
|
|
||||||
import org.mapstruct.ap.model.common.Parameter;
|
import org.mapstruct.ap.model.common.Parameter;
|
||||||
@ -27,7 +26,6 @@ import org.mapstruct.ap.model.common.Type;
|
|||||||
import org.mapstruct.ap.model.common.TypeFactory;
|
import org.mapstruct.ap.model.common.TypeFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Sjaak Derksen
|
* @author Sjaak Derksen
|
||||||
*/
|
*/
|
||||||
public class ListOfJaxbElemToListOfValue extends BuiltInMethod {
|
public class ListOfJaxbElemToListOfValue extends BuiltInMethod {
|
||||||
@ -36,8 +34,8 @@ public class ListOfJaxbElemToListOfValue extends BuiltInMethod {
|
|||||||
private final Type returnType;
|
private final Type returnType;
|
||||||
private final Type genericParam;
|
private final Type genericParam;
|
||||||
|
|
||||||
public ListOfJaxbElemToListOfValue( TypeFactory typeFactory ) {
|
public ListOfJaxbElemToListOfValue(TypeFactory typeFactory) {
|
||||||
this.parameter = typeFactory.createParameter( "elementList", List.class );
|
this.parameter = new Parameter( "elementList", typeFactory.getType( List.class ) );
|
||||||
this.returnType = typeFactory.getType( List.class );
|
this.returnType = typeFactory.getType( List.class );
|
||||||
this.genericParam = typeFactory.getType( JAXBElement.class ).erasure();
|
this.genericParam = typeFactory.getType( JAXBElement.class ).erasure();
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@ import java.text.ParseException;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.xml.datatype.DatatypeConfigurationException;
|
import javax.xml.datatype.DatatypeConfigurationException;
|
||||||
import javax.xml.datatype.DatatypeFactory;
|
import javax.xml.datatype.DatatypeFactory;
|
||||||
import javax.xml.datatype.XMLGregorianCalendar;
|
import javax.xml.datatype.XMLGregorianCalendar;
|
||||||
@ -36,31 +35,31 @@ import org.mapstruct.ap.model.common.TypeFactory;
|
|||||||
import static org.mapstruct.ap.util.Collections.asSet;
|
import static org.mapstruct.ap.util.Collections.asSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Sjaak Derksen
|
* @author Sjaak Derksen
|
||||||
*/
|
*/
|
||||||
public class StringToXmlGregorianCalendar extends BuiltInMethod {
|
public class StringToXmlGregorianCalendar extends BuiltInMethod {
|
||||||
|
|
||||||
private final Parameter parameter;
|
private final Parameter parameter;
|
||||||
private final Type returnType;
|
private final Type returnType;
|
||||||
|
private final Set<Type> importTypes;
|
||||||
|
|
||||||
private final TypeFactory typeFactory;
|
|
||||||
|
|
||||||
public StringToXmlGregorianCalendar( TypeFactory typeFactory ) {
|
public StringToXmlGregorianCalendar(TypeFactory typeFactory) {
|
||||||
this.typeFactory = typeFactory;
|
this.parameter = new Parameter( "date", typeFactory.getType( String.class ) );
|
||||||
this.parameter = typeFactory.createParameter( "date" , String.class );
|
|
||||||
this.returnType = typeFactory.getType( XMLGregorianCalendar.class );
|
this.returnType = typeFactory.getType( XMLGregorianCalendar.class );
|
||||||
|
this.importTypes = asSet(
|
||||||
}
|
typeFactory.getType( GregorianCalendar.class ),
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<Type> getImportTypes() {
|
|
||||||
return asSet( new Type[]{ typeFactory.getType( GregorianCalendar.class ),
|
|
||||||
typeFactory.getType( SimpleDateFormat.class ),
|
typeFactory.getType( SimpleDateFormat.class ),
|
||||||
typeFactory.getType( DateFormat.class ),
|
typeFactory.getType( DateFormat.class ),
|
||||||
typeFactory.getType( ParseException.class ),
|
typeFactory.getType( ParseException.class ),
|
||||||
typeFactory.getType( DatatypeFactory.class ),
|
typeFactory.getType( DatatypeFactory.class ),
|
||||||
typeFactory.getType( DatatypeConfigurationException.class ) });
|
typeFactory.getType( DatatypeConfigurationException.class )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<Type> getImportTypes() {
|
||||||
|
return importTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
package org.mapstruct.ap.model.source.builtin;
|
package org.mapstruct.ap.model.source.builtin;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
|
||||||
import javax.xml.datatype.XMLGregorianCalendar;
|
import javax.xml.datatype.XMLGregorianCalendar;
|
||||||
|
|
||||||
import org.mapstruct.ap.model.common.Parameter;
|
import org.mapstruct.ap.model.common.Parameter;
|
||||||
@ -27,7 +26,6 @@ import org.mapstruct.ap.model.common.Type;
|
|||||||
import org.mapstruct.ap.model.common.TypeFactory;
|
import org.mapstruct.ap.model.common.TypeFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Sjaak Derksen
|
* @author Sjaak Derksen
|
||||||
*/
|
*/
|
||||||
public class XmlGregorianCalendarToCalendar extends BuiltInMethod {
|
public class XmlGregorianCalendarToCalendar extends BuiltInMethod {
|
||||||
@ -35,8 +33,8 @@ public class XmlGregorianCalendarToCalendar extends BuiltInMethod {
|
|||||||
private final Parameter parameter;
|
private final Parameter parameter;
|
||||||
private final Type returnType;
|
private final Type returnType;
|
||||||
|
|
||||||
public XmlGregorianCalendarToCalendar( TypeFactory typeFactory ) {
|
public XmlGregorianCalendarToCalendar(TypeFactory typeFactory) {
|
||||||
this.parameter = typeFactory.createParameter( "xcal", XMLGregorianCalendar.class );
|
this.parameter = new Parameter( "xcal", typeFactory.getType( XMLGregorianCalendar.class ) );
|
||||||
this.returnType = typeFactory.getType( Calendar.class );
|
this.returnType = typeFactory.getType( Calendar.class );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
package org.mapstruct.ap.model.source.builtin;
|
package org.mapstruct.ap.model.source.builtin;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import javax.xml.datatype.XMLGregorianCalendar;
|
import javax.xml.datatype.XMLGregorianCalendar;
|
||||||
|
|
||||||
import org.mapstruct.ap.model.common.Parameter;
|
import org.mapstruct.ap.model.common.Parameter;
|
||||||
@ -27,7 +26,6 @@ import org.mapstruct.ap.model.common.Type;
|
|||||||
import org.mapstruct.ap.model.common.TypeFactory;
|
import org.mapstruct.ap.model.common.TypeFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Sjaak Derksen
|
* @author Sjaak Derksen
|
||||||
*/
|
*/
|
||||||
public class XmlGregorianCalendarToDate extends BuiltInMethod {
|
public class XmlGregorianCalendarToDate extends BuiltInMethod {
|
||||||
@ -35,8 +33,8 @@ public class XmlGregorianCalendarToDate extends BuiltInMethod {
|
|||||||
private final Parameter parameter;
|
private final Parameter parameter;
|
||||||
private final Type returnType;
|
private final Type returnType;
|
||||||
|
|
||||||
public XmlGregorianCalendarToDate( TypeFactory typeFactory ) {
|
public XmlGregorianCalendarToDate(TypeFactory typeFactory) {
|
||||||
this.parameter = typeFactory.createParameter( "xcal", XMLGregorianCalendar.class );
|
this.parameter = new Parameter( "xcal", typeFactory.getType( XMLGregorianCalendar.class ) );
|
||||||
this.returnType = typeFactory.getType( Date.class );
|
this.returnType = typeFactory.getType( Date.class );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ import org.mapstruct.ap.model.common.Type;
|
|||||||
import org.mapstruct.ap.model.common.TypeFactory;
|
import org.mapstruct.ap.model.common.TypeFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Sjaak Derksen
|
* @author Sjaak Derksen
|
||||||
*/
|
*/
|
||||||
public class XmlGregorianCalendarToString extends BuiltInMethod {
|
public class XmlGregorianCalendarToString extends BuiltInMethod {
|
||||||
@ -34,8 +33,8 @@ public class XmlGregorianCalendarToString extends BuiltInMethod {
|
|||||||
private final Parameter parameter;
|
private final Parameter parameter;
|
||||||
private final Type returnType;
|
private final Type returnType;
|
||||||
|
|
||||||
public XmlGregorianCalendarToString( TypeFactory typeFactory ) {
|
public XmlGregorianCalendarToString(TypeFactory typeFactory) {
|
||||||
this.parameter = typeFactory.createParameter( "xcal" , XMLGregorianCalendar.class );
|
this.parameter = new Parameter( "xcal", typeFactory.getType( XMLGregorianCalendar.class ) );
|
||||||
this.returnType = typeFactory.getType( String.class );
|
this.returnType = typeFactory.getType( String.class );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user