Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -958,9 +958,8 @@ private List<Accessor> getAccessorCandidates(Type property, Class<?> superclass)
List<Accessor> adderList = getAdders();
List<Accessor> candidateList = new ArrayList<>();
for ( Accessor adder : adderList ) {
ExecutableElement executable = (ExecutableElement) adder.getElement();
VariableElement arg = executable.getParameters().get( 0 );
if ( typeUtils.isSameType( boxed( arg.asType() ), boxed( typeArg ) ) ) {
TypeMirror adderParameterType = determineTargetType( adder ).getTypeMirror();
if ( typeUtils.isSameType( boxed( adderParameterType ), boxed( typeArg ) ) ) {
candidateList.add( adder );
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._3310;

import java.util.ArrayList;
import java.util.List;

import org.mapstruct.CollectionMappingStrategy;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

/**
* @author Filip Hrisafov
*/
@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED)
public interface Issue3310Mapper {

Issue3310Mapper INSTANCE = Mappers.getMapper( Issue3310Mapper.class );

Target map(Source source);

abstract class BaseClass<T> {

private List<T> items;

public List<T> getItems() {
return items;
}

public void setItems(List<T> items) {
throw new UnsupportedOperationException( "adder should be used instead" );
}

public void addItem(T item) {
if ( items == null ) {
items = new ArrayList<>();
}
items.add( item );
}
}

class Target extends BaseClass<String> {

}

class Source {

private final List<String> items;

public Source(List<String> items) {
this.items = items;
}

public List<String> getItems() {
return items;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._3310;

import java.util.Collections;

import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses;

import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Filip Hrisafov
*/
@IssueKey("3310")
@WithClasses(Issue3310Mapper.class)
class Issue3310Test {

@ProcessorTest
void shouldUseAdderWithGenericBaseClass() {
Issue3310Mapper.Source source = new Issue3310Mapper.Source( Collections.singletonList( "test" ) );
Issue3310Mapper.Target target = Issue3310Mapper.INSTANCE.map( source );

assertThat( target ).isNotNull();
assertThat( target.getItems() ).containsExactly( "test" );
}
}