use of org.mapstruct.ap.internal.model.common.Parameter in project mapstruct by mapstruct.
the class TypeSelector method getAvailableParameterBindingsFromSourceTypes.
private List<ParameterBinding> getAvailableParameterBindingsFromSourceTypes(List<Type> sourceTypes, Type targetType, Method mappingMethod) {
List<ParameterBinding> availableParams = new ArrayList<ParameterBinding>(sourceTypes.size() + 2);
addMappingTargetAndTargetTypeBindings(availableParams, targetType);
for (Type sourceType : sourceTypes) {
availableParams.add(ParameterBinding.forSourceTypeBinding(sourceType));
}
for (Parameter param : mappingMethod.getParameters()) {
if (param.isMappingContext()) {
availableParams.add(ParameterBinding.fromParameter(param));
}
}
return availableParams;
}
use of org.mapstruct.ap.internal.model.common.Parameter in project mapstruct by mapstruct.
the class InheritanceSelector method getMatchingMethods.
@Override
public <T extends Method> List<SelectedMethod<T>> getMatchingMethods(Method mappingMethod, List<SelectedMethod<T>> methods, List<Type> sourceTypes, Type targetType, SelectionCriteria criteria) {
if (sourceTypes.size() != 1) {
return methods;
}
Type singleSourceType = first(sourceTypes);
List<SelectedMethod<T>> candidatesWithBestMatchingSourceType = new ArrayList<SelectedMethod<T>>();
int bestMatchingSourceTypeDistance = Integer.MAX_VALUE;
// find the methods with the minimum distance regarding getParameter getParameter type
for (SelectedMethod<T> method : methods) {
Parameter singleSourceParam = first(method.getMethod().getSourceParameters());
int sourceTypeDistance = singleSourceType.distanceTo(singleSourceParam.getType());
bestMatchingSourceTypeDistance = addToCandidateListIfMinimal(candidatesWithBestMatchingSourceType, bestMatchingSourceTypeDistance, method, sourceTypeDistance);
}
return candidatesWithBestMatchingSourceType;
}
use of org.mapstruct.ap.internal.model.common.Parameter in project mapstruct by mapstruct.
the class MethodRetrievalProcessor method isValidReferencedOrFactoryMethod.
private boolean isValidReferencedOrFactoryMethod(int sourceParamCount, int targetParamCount, List<Parameter> parameters) {
int validSourceParameters = 0;
int targetParameters = 0;
int targetTypeParameters = 0;
for (Parameter param : parameters) {
if (param.isMappingTarget()) {
targetParameters++;
} else if (param.isTargetType()) {
targetTypeParameters++;
} else if (!param.isMappingContext()) {
validSourceParameters++;
}
}
return validSourceParameters == sourceParamCount && targetParameters <= targetParamCount && targetTypeParameters <= 1;
}
use of org.mapstruct.ap.internal.model.common.Parameter in project mapstruct by mapstruct.
the class MethodRetrievalProcessor method retrievePrototypeMethods.
private List<SourceMethod> retrievePrototypeMethods(TypeElement mapperTypeElement, MapperConfiguration mapperConfig) {
if (mapperConfig.config() == null) {
return Collections.emptyList();
}
TypeElement typeElement = asTypeElement(mapperConfig.config());
List<SourceMethod> methods = new ArrayList<SourceMethod>();
for (ExecutableElement executable : getAllEnclosedExecutableElements(elementUtils, typeElement)) {
ExecutableType methodType = typeFactory.getMethodType(mapperConfig.config(), executable);
List<Parameter> parameters = typeFactory.getParameters(methodType, executable);
boolean containsTargetTypeParameter = SourceMethod.containsTargetTypeParameter(parameters);
// prototype methods don't have prototypes themselves
List<SourceMethod> prototypeMethods = Collections.emptyList();
SourceMethod method = getMethodRequiringImplementation(methodType, executable, parameters, containsTargetTypeParameter, mapperConfig, prototypeMethods, mapperTypeElement);
if (method != null) {
methods.add(method);
}
}
return methods;
}
use of org.mapstruct.ap.internal.model.common.Parameter in project mapstruct by mapstruct.
the class MethodRetrievalProcessor method getMethod.
private SourceMethod getMethod(TypeElement usedMapper, ExecutableElement method, TypeElement mapperToImplement, MapperConfiguration mapperConfig, List<SourceMethod> prototypeMethods) {
ExecutableType methodType = typeFactory.getMethodType((DeclaredType) usedMapper.asType(), method);
List<Parameter> parameters = typeFactory.getParameters(methodType, method);
Type returnType = typeFactory.getReturnType(methodType);
boolean methodRequiresImplementation = method.getModifiers().contains(Modifier.ABSTRACT);
boolean containsTargetTypeParameter = SourceMethod.containsTargetTypeParameter(parameters);
// add method with property mappings if an implementation needs to be generated
if ((usedMapper.equals(mapperToImplement)) && methodRequiresImplementation) {
return getMethodRequiringImplementation(methodType, method, parameters, containsTargetTypeParameter, mapperConfig, prototypeMethods, mapperToImplement);
} else // otherwise add reference to existing mapper method
if (isValidReferencedMethod(parameters) || isValidFactoryMethod(method, parameters, returnType) || isValidLifecycleCallbackMethod(method, returnType)) {
return getReferencedMethod(usedMapper, methodType, method, mapperToImplement, parameters);
} else {
return null;
}
}
Aggregations