diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java index 3f4bf0c41..4b7bbbb7e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java @@ -75,6 +75,7 @@ public class GetterWrapperForCollectionsAndMaps extends AssignmentWrapper { Set imported = new HashSet(); imported.addAll( super.getImportTypes() ); imported.add( localVarType ); /* is a local var */ + imported.addAll( localVarType.getTypeParameters() ); return imported; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Issue849Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Issue849Mapper.java new file mode 100644 index 000000000..c80ae809c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Issue849Mapper.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._849; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Sjaak Derksen + */ +@Mapper +public interface Issue849Mapper { + + Issue849Mapper INSTANCE = Mappers.getMapper( Issue849Mapper.class ); + + @Mapping(source = "sourceList", target = "targetList") + Target mapSourceToTarget(Source source); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Issue849Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Issue849Test.java new file mode 100644 index 000000000..62a7c9327 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Issue849Test.java @@ -0,0 +1,50 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._849; + +import java.io.Serializable; +import java.util.Arrays; +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Andreas Gudian + * + */ +@WithClasses({ Source.class, Target.class, Issue849Mapper.class }) +@RunWith(AnnotationProcessorTestRunner.class) +public class Issue849Test { + + @Test + @IssueKey("849") + public void shouldCompileWithAllImportsDeclared() { + + Source source = new Source(); + source.setSourceList( Arrays.asList( (Serializable) "test" ) ); + + Target target = Issue849Mapper.INSTANCE.mapSourceToTarget( source ); + assertThat( target.getTargetList() ).containsExactly( "test" ); + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Source.java new file mode 100644 index 000000000..47f61483c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Source.java @@ -0,0 +1,39 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._849; + +import java.io.Serializable; +import java.util.List; + +/** + * + * @author Sjaak Derksen + */ +public class Source { + + private List sourceList; + + public List getSourceList() { + return sourceList; + } + + public void setSourceList(List sourceList) { + this.sourceList = sourceList; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Target.java new file mode 100644 index 000000000..00458abe6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Target.java @@ -0,0 +1,40 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._849; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author Sjaak Derksen + */ +public class Target { + + private List targetList; + + public List getTargetList() { + if ( targetList == null ) { + targetList = new ArrayList(); + } + return targetList; + } + +}