Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/2954 allowing generic mappings #2959

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Zegveld
Copy link
Contributor

@Zegveld Zegveld commented Aug 15, 2022

First step in allowing generic mappings as long as the generic itself doesn't change.

closes #2954

@filiphr
Copy link
Member

filiphr commented Aug 17, 2022

I am not sure that we should relax the requirement we have for this. However, I am going to look into the PR into detail a bit later.

@filiphr
Copy link
Member

filiphr commented Sep 21, 2022

I need to play around with this to see what happens when the sources are not generic themselves.

Copy link
Member

@filiphr filiphr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a look at this @Zegveld and I have some questions for some things that I couldn't understand.

I am also not sure that support a type parameter for the @Context parameter makes sense here. The @Context parameter is meant to be passed to other places, e.g. @AfterMapping, @BeforeMapping, etc. How will this affect that functionality?

I think that we should limit the generic support only to valid source parameters and nothing more.

How does this work with @MappingTarget parameters?

GenericSourceContainer<String> container = new GenericSourceContainer<>( containedObject, "otherValue" );

GenericTargetContainer<String> resultString = GenericContainerMapper.INSTANCE.map( container );
assertThat( resultString.getContained() ).isSameAs( containedObject );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing isSameAs with a String isn't really recommended. If we want to test this properly we should use some other object.

Integer replacement = 1234;
GenericTargetContainer<Integer> resultContext =
GenericContainerMapper.INSTANCE.mapWithContext( container, replacement );
assertThat( resultContext.getContained() ).isSameAs( replacement );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same story here, we can't be using isSameAs for integer. We should try with actual objects here.


GenericTargetContainer<Integer> resultSecondParameter =
GenericContainerMapper.INSTANCE.mapWithSecondParameter( container, replacement );
assertThat( resultSecondParameter.getContained() ).isSameAs( replacement );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same story here for the isSameAs

@@ -96,6 +96,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
private final MethodReference finalizerMethod;

private final MappingReferences mappingReferences;
private List<Type> typeParameters;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we make this final? I also see that this is not in the getImportTypes(). How will it with with things such as extends and super?

@@ -552,7 +549,7 @@ private boolean checkParameterAndReturnType(ExecutableElement method, List<Param
}

for ( Type typeParameter : resultType.getTypeParameters() ) {
if ( typeParameter.isTypeVar() ) {
if ( resultType.isIterableOrStreamType() && typeParameter.isTypeVar() ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to check the resultType here?

for ( Type typeParameter : parameterType.getTypeParameters() ) {
if ( typeParameter.hasSuperBound() ) {
messager.printMessage( method, Message.RETRIEVAL_WILDCARD_SUPER_BOUND_SOURCE );
return false;
}

if ( typeParameter.isTypeVar() ) {
if ( parameterType.isIterableOrStreamType() && resultType.isIterableOrStreamType()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to check for isIterableOrStreamType here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generic type use , An error was obtained --- Can't generate mapping method for a generic type variable source.
2 participants