mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#2945 Stabilise top level imports
Make sure that GeneratedType always gets the imported types from a Type before adding them
This commit is contained in:
parent
b24e831cf0
commit
71b1a7b8a2
@ -258,8 +258,10 @@ public abstract class GeneratedType extends ModelElement {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( needsImportDeclaration( typeToAdd ) ) {
|
||||
collection.add( typeToAdd );
|
||||
for ( Type type : typeToAdd.getImportTypes() ) {
|
||||
if ( needsImportDeclaration( type ) ) {
|
||||
collection.add( type );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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._2945;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ap.test.bugs._2945._target.Target;
|
||||
import org.mapstruct.ap.test.bugs._2945.source.Source;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* @author Filip Hrisafov
|
||||
*/
|
||||
@Mapper
|
||||
public interface Issue2945Mapper {
|
||||
|
||||
Issue2945Mapper INSTANCE = Mappers.getMapper( Issue2945Mapper.class );
|
||||
|
||||
Target map(Source source);
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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._2945;
|
||||
|
||||
import org.mapstruct.ap.test.bugs._2945._target.EnumHolder;
|
||||
import org.mapstruct.ap.test.bugs._2945._target.Target;
|
||||
import org.mapstruct.ap.test.bugs._2945.source.Source;
|
||||
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("2945")
|
||||
@WithClasses({
|
||||
EnumHolder.class,
|
||||
Issue2945Mapper.class,
|
||||
Source.class,
|
||||
Target.class,
|
||||
})
|
||||
class Issue2945Test {
|
||||
|
||||
@ProcessorTest
|
||||
void shouldCompile() {
|
||||
Target target = Issue2945Mapper.INSTANCE.map( new Source( "VALUE_1" ) );
|
||||
|
||||
assertThat( target.getProperty() ).isEqualTo( EnumHolder.Property.VALUE_1 );
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* 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._2945._target;
|
||||
|
||||
public class EnumHolder {
|
||||
public enum Property {
|
||||
VALUE_1,
|
||||
VALUE_2;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* 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._2945._target;
|
||||
|
||||
public class Target {
|
||||
private EnumHolder.Property property;
|
||||
|
||||
public EnumHolder.Property getProperty() {
|
||||
return property;
|
||||
}
|
||||
|
||||
public void setProperty(EnumHolder.Property property) {
|
||||
this.property = property;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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._2945.source;
|
||||
|
||||
/**
|
||||
* @author Filip Hrisafov
|
||||
*/
|
||||
public class Source {
|
||||
|
||||
private final String property;
|
||||
|
||||
public Source(String property) {
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
public String getProperty() {
|
||||
return property;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user