mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#178 fix a new unused import that crept in, added a test for it
This commit is contained in:
parent
a1cdd11bd5
commit
c8f6be3204
@ -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() );
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -37,4 +37,8 @@ public class GenericMapper {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public NotImportedDatatype identity(NotImportedDatatype notImported) {
|
||||
return notImported;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user