mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#136 Some clean-up/documentation
This commit is contained in:
parent
4372e726ee
commit
1db853137c
@ -18,12 +18,12 @@
|
||||
*/
|
||||
package org.mapstruct.ap.model;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import org.mapstruct.ap.model.common.ConversionContext;
|
||||
import org.mapstruct.ap.model.common.Parameter;
|
||||
import org.mapstruct.ap.model.common.Type;
|
||||
import org.mapstruct.ap.model.source.Method;
|
||||
import org.mapstruct.ap.model.source.SourceMethod;
|
||||
import org.mapstruct.ap.model.source.builtin.BuiltInMethod;
|
||||
|
||||
@ -35,7 +35,7 @@ import org.mapstruct.ap.model.source.builtin.BuiltInMethod;
|
||||
public class MethodReference extends MappingMethod {
|
||||
|
||||
private final MapperReference declaringMapper;
|
||||
private final Type importType;
|
||||
private final Set<Type> importTypes;
|
||||
|
||||
/**
|
||||
* A reference to another mapping method in case this is a two-step mapping, e.g. from {@code JAXBElement<Bar>} to
|
||||
@ -51,25 +51,27 @@ public class MethodReference extends MappingMethod {
|
||||
*/
|
||||
private final String contextParam;
|
||||
|
||||
public MethodReference(SourceMethod method, MapperReference declaringMapper) {
|
||||
/**
|
||||
* Creates a new reference to the given method.
|
||||
* @param method the target method of the reference
|
||||
* @param declaringMapper the method declaring the mapper; {@code null} if the current mapper itself
|
||||
* @param targetType in case the referenced method has a parameter for passing the target type, the given
|
||||
* target type, otherwise {@code null}
|
||||
*/
|
||||
public MethodReference(SourceMethod method, MapperReference declaringMapper, Type targetType) {
|
||||
super( method );
|
||||
this.declaringMapper = declaringMapper;
|
||||
this.contextParam = null;
|
||||
this.importType = null;
|
||||
this.importTypes = targetType == null ?
|
||||
Collections.<Type>emptySet() :
|
||||
Collections.<Type>singleton( targetType );
|
||||
}
|
||||
|
||||
public MethodReference(BuiltInMethod method, ConversionContext contextParam) {
|
||||
super( method );
|
||||
this.declaringMapper = null;
|
||||
this.contextParam = method.getContextParameter( contextParam );
|
||||
this.importType = null;
|
||||
}
|
||||
|
||||
public MethodReference(Method method, MapperReference declaringMapper, Type importType) {
|
||||
super( method );
|
||||
this.declaringMapper = declaringMapper;
|
||||
this.contextParam = null;
|
||||
this.importType = importType;
|
||||
this.importTypes = Collections.emptySet();
|
||||
}
|
||||
|
||||
public MapperReference getDeclaringMapper() {
|
||||
@ -107,9 +109,7 @@ public class MethodReference extends MappingMethod {
|
||||
@Override
|
||||
public Set<Type> getImportTypes() {
|
||||
Set<Type> imported = super.getImportTypes();
|
||||
if ( importType != null ) {
|
||||
imported.add( importType );
|
||||
}
|
||||
imported.addAll( importTypes );
|
||||
if ( methodRefChild != null ) {
|
||||
imported.addAll( methodRefChild.getImportTypes() );
|
||||
}
|
||||
|
@ -259,19 +259,13 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
||||
if ( !method.requiresImplementation() && !method.isIterableMapping() && !method.isMapMapping()
|
||||
&& method.getSourceParameters().size() == 0 ) {
|
||||
|
||||
List<Type> paramterTypes =
|
||||
List<Type> parameterTypes =
|
||||
MethodSelectors.getParameterTypes( typeFactory, method.getParameters(), null, returnType );
|
||||
|
||||
if ( method.matches( paramterTypes, returnType ) ) {
|
||||
if ( method.matches( parameterTypes, returnType ) ) {
|
||||
if ( result == null ) {
|
||||
MapperReference mapperReference = findMapperReference( mapperReferences, method );
|
||||
|
||||
result =
|
||||
new MethodReference(
|
||||
method,
|
||||
mapperReference,
|
||||
SourceMethod.containsTargetTypeParameter( method.getParameters() )
|
||||
? returnType : null );
|
||||
result = new MethodReference( method, mapperReference, null );
|
||||
}
|
||||
else {
|
||||
messager.printMessage(
|
||||
@ -1155,7 +1149,8 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
||||
return new MethodReference(
|
||||
method,
|
||||
mapperReference,
|
||||
SourceMethod.containsTargetTypeParameter( method.getParameters() ) ? targetType : null );
|
||||
SourceMethod.containsTargetTypeParameter( method.getParameters() ) ? targetType : null
|
||||
);
|
||||
}
|
||||
|
||||
private MapperReference findMapperReference(List<MapperReference> mapperReferences, SourceMethod method) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user