use of org.mapstruct.ap.internal.model.common.Parameter in project mapstruct by mapstruct.
the class SourceMethod method getParameterNames.
@Override
public List<String> getParameterNames() {
if (parameterNames == null) {
List<String> names = new ArrayList<String>(parameters.size());
for (Parameter parameter : parameters) {
names.add(parameter.getName());
}
parameterNames = Collections.unmodifiableList(names);
}
return parameterNames;
}
use of org.mapstruct.ap.internal.model.common.Parameter in project mapstruct by mapstruct.
the class SourceMethod method allParametersAreAssignable.
private static boolean allParametersAreAssignable(List<Parameter> fromParams, List<Parameter> toParams) {
if (fromParams.size() == toParams.size()) {
Set<Parameter> unaccountedToParams = new HashSet<Parameter>(toParams);
for (Parameter fromParam : fromParams) {
// each fromParam needs at least one match, and all toParam need to be accounted for at the end
boolean hasMatch = false;
for (Parameter toParam : toParams) {
if (fromParam.getType().isAssignableTo(toParam.getType())) {
unaccountedToParams.remove(toParam);
hasMatch = true;
}
}
if (!hasMatch) {
return false;
}
}
return unaccountedToParams.isEmpty();
}
return false;
}
use of org.mapstruct.ap.internal.model.common.Parameter in project mapstruct by mapstruct.
the class MappingMethod method getImportTypes.
@Override
public Set<Type> getImportTypes() {
Set<Type> types = new HashSet<Type>();
for (Parameter param : parameters) {
types.addAll(param.getType().getImportTypes());
}
types.addAll(getReturnType().getImportTypes());
for (Type type : thrownTypes) {
types.addAll(type.getImportTypes());
}
return types;
}
use of org.mapstruct.ap.internal.model.common.Parameter in project mapstruct by mapstruct.
the class MethodRetrievalProcessor method retrieveLifecycleMethodsFromContext.
private ParameterProvidedMethods retrieveLifecycleMethodsFromContext(List<Parameter> contextParameters, TypeElement mapperToImplement, MapperConfiguration mapperConfig) {
ParameterProvidedMethods.Builder builder = ParameterProvidedMethods.builder();
for (Parameter contextParam : contextParameters) {
if (contextParam.getType().isPrimitive()) {
continue;
}
List<SourceMethod> contextParamMethods = retrieveMethods(contextParam.getType().getTypeElement(), mapperToImplement, mapperConfig, Collections.<SourceMethod>emptyList());
List<SourceMethod> lifecycleMethods = new ArrayList<SourceMethod>(contextParamMethods.size());
for (SourceMethod sourceMethod : contextParamMethods) {
if (sourceMethod.isLifecycleCallbackMethod()) {
lifecycleMethods.add(sourceMethod);
}
}
builder.addMethodsForParameter(contextParam, lifecycleMethods);
}
return builder.build();
}
use of org.mapstruct.ap.internal.model.common.Parameter in project mapstruct by mapstruct.
the class MethodRetrievalProcessor method checkParameterAndReturnType.
private boolean checkParameterAndReturnType(ExecutableElement method, List<Parameter> sourceParameters, Parameter targetParameter, List<Parameter> contextParameters, Type resultType, Type returnType, boolean containsTargetTypeParameter) {
if (sourceParameters.isEmpty()) {
messager.printMessage(method, Message.RETRIEVAL_NO_INPUT_ARGS);
return false;
}
if (targetParameter != null && (sourceParameters.size() + contextParameters.size() + 1 != method.getParameters().size())) {
messager.printMessage(method, Message.RETRIEVAL_DUPLICATE_MAPPING_TARGETS);
return false;
}
if (isVoid(resultType)) {
messager.printMessage(method, Message.RETRIEVAL_VOID_MAPPING_METHOD);
return false;
}
if (returnType.getTypeMirror().getKind() != TypeKind.VOID && !resultType.isAssignableTo(returnType)) {
messager.printMessage(method, Message.RETRIEVAL_NON_ASSIGNABLE_RESULTTYPE);
return false;
}
for (Parameter sourceParameter : sourceParameters) {
if (sourceParameter.getType().isTypeVar()) {
messager.printMessage(method, Message.RETRIEVAL_TYPE_VAR_SOURCE);
return false;
}
}
Set<Type> contextParameterTypes = new HashSet<Type>();
for (Parameter contextParameter : contextParameters) {
if (!contextParameterTypes.add(contextParameter.getType())) {
messager.printMessage(method, Message.RETRIEVAL_CONTEXT_PARAMS_WITH_SAME_TYPE);
return false;
}
}
if (returnType.isTypeVar() || resultType.isTypeVar()) {
messager.printMessage(method, Message.RETRIEVAL_TYPE_VAR_RESULT);
return false;
}
Type parameterType = sourceParameters.get(0).getType();
if (parameterType.isIterableOrStreamType() && !resultType.isIterableOrStreamType()) {
messager.printMessage(method, Message.RETRIEVAL_ITERABLE_TO_NON_ITERABLE);
return false;
}
if (containsTargetTypeParameter) {
messager.printMessage(method, Message.RETRIEVAL_MAPPING_HAS_TARGET_TYPE_PARAMETER);
return false;
}
if (!parameterType.isIterableOrStreamType() && resultType.isIterableOrStreamType()) {
messager.printMessage(method, Message.RETRIEVAL_NON_ITERABLE_TO_ITERABLE);
return false;
}
if (parameterType.isPrimitive()) {
messager.printMessage(method, Message.RETRIEVAL_PRIMITIVE_PARAMETER);
return false;
}
if (resultType.isPrimitive()) {
messager.printMessage(method, Message.RETRIEVAL_PRIMITIVE_RETURN);
return false;
}
if (parameterType.isEnumType() && !resultType.isEnumType()) {
messager.printMessage(method, Message.RETRIEVAL_ENUM_TO_NON_ENUM);
return false;
}
if (!parameterType.isEnumType() && resultType.isEnumType()) {
messager.printMessage(method, Message.RETRIEVAL_NON_ENUM_TO_ENUM);
return false;
}
for (Type typeParameter : resultType.getTypeParameters()) {
if (typeParameter.isTypeVar()) {
messager.printMessage(method, Message.RETRIEVAL_TYPE_VAR_RESULT);
return false;
}
if (typeParameter.isWildCardExtendsBound()) {
messager.printMessage(method, Message.RETRIEVAL_WILDCARD_EXTENDS_BOUND_RESULT);
return false;
}
}
for (Type typeParameter : parameterType.getTypeParameters()) {
if (typeParameter.isWildCardSuperBound()) {
messager.printMessage(method, Message.RETRIEVAL_WILDCARD_SUPER_BOUND_SOURCE);
return false;
}
if (typeParameter.isTypeVar()) {
messager.printMessage(method, Message.RETRIEVAL_TYPE_VAR_SOURCE);
return false;
}
}
return true;
}
Aggregations