#178 fix a new unused import that crept in, added a test for it

This commit is contained in:
Andreas Gudian 2014-06-01 17:01:02 +02:00 committed by Gunnar Morling
parent a1cdd11bd5
commit c8f6be3204
4 changed files with 17 additions and 3 deletions

View File

@ -23,11 +23,11 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.mapstruct.ap.model.Assignment;
import org.mapstruct.ap.model.FactoryMethod;
import org.mapstruct.ap.model.MapperReference;
import org.mapstruct.ap.model.MappingMethod;
import org.mapstruct.ap.model.common.ConversionContext;
import org.mapstruct.ap.model.common.Parameter;
import org.mapstruct.ap.model.common.Type;
@ -74,7 +74,7 @@ public class MethodReference extends MappingMethod implements Assignment, Factor
super( method );
this.declaringMapper = declaringMapper;
this.contextParam = null;
Set<Type> imported = new HashSet( method.getThrownTypes() );
Set<Type> imported = new HashSet<Type>( method.getThrownTypes() );
if ( targetType != null ) {
imported.add( targetType );
}
@ -130,7 +130,7 @@ public class MethodReference extends MappingMethod implements Assignment, Factor
@Override
public Set<Type> getImportTypes() {
Set<Type> imported = org.mapstruct.ap.util.Collections.asSet( importTypes, super.getImportTypes() );
Set<Type> imported = new HashSet<Type>( importTypes );
if ( assignment != null ) {
imported.addAll( assignment.getImportTypes() );
}

View File

@ -95,7 +95,13 @@ public class ConflictingTypesNamesTest {
assertThat( target ).isNotNull();
assertThat( target.getNotImported() ).isSameAs( source.getNotImported() );
target = SecondSourceTargetMapper.INSTANCE.sourceToTarget( source );
assertThat( target ).isNotNull();
assertThat( target.getNotImported() ).isSameAs( source.getNotImported() );
generatedSource.forMapper( SourceTargetMapper.class ).containsNoImportFor( NotImportedDatatype.class );
generatedSource.forMapper( SecondSourceTargetMapper.class ).containsNoImportFor( NotImportedDatatype.class );
}
@Test

View File

@ -20,6 +20,8 @@ package org.mapstruct.ap.test.imports;
import org.mapstruct.Mapper;
import org.mapstruct.ap.test.imports.referenced.GenericMapper;
import org.mapstruct.ap.test.imports.referenced.Source;
import org.mapstruct.ap.test.imports.referenced.Target;
import org.mapstruct.ap.test.imports.to.FooWrapper;
import org.mapstruct.factory.Mappers;
@ -32,4 +34,6 @@ public interface SecondSourceTargetMapper {
SecondSourceTargetMapper INSTANCE = Mappers.getMapper( SecondSourceTargetMapper.class );
FooWrapper fooWrapperToFooWrapper(org.mapstruct.ap.test.imports.from.FooWrapper foo);
Target sourceToTarget(Source source);
}

View File

@ -37,4 +37,8 @@ public class GenericMapper {
return null;
}
public NotImportedDatatype identity(NotImportedDatatype notImported) {
return notImported;
}
}