mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#2880 Fix missing import for array mapping methods
Co-authored-by: Martin Kamp Jensen <martin.kamp.jensen@se.com>
This commit is contained in:
parent
fa800926e7
commit
98eb46aee9
@ -181,8 +181,11 @@ public class Type extends ModelElement implements Comparable<Type> {
|
||||
|
||||
this.loggingVerbose = loggingVerbose;
|
||||
|
||||
this.topLevelType = topLevelType( this.typeElement, this.typeFactory );
|
||||
this.nameWithTopLevelTypeName = nameWithTopLevelTypeName( this.typeElement );
|
||||
// The top level type for an array type is the top level type of the component type
|
||||
TypeElement typeElementForTopLevel =
|
||||
this.componentType == null ? this.typeElement : this.componentType.getTypeElement();
|
||||
this.topLevelType = topLevelType( typeElementForTopLevel, this.typeFactory );
|
||||
this.nameWithTopLevelTypeName = nameWithTopLevelTypeName( typeElementForTopLevel, this.name );
|
||||
}
|
||||
//CHECKSTYLE:ON
|
||||
|
||||
@ -218,7 +221,17 @@ public class Type extends ModelElement implements Comparable<Type> {
|
||||
* (if the top level type is important, otherwise the fully-qualified name.
|
||||
*/
|
||||
public String createReferenceName() {
|
||||
if ( isToBeImported() || shouldUseSimpleName() ) {
|
||||
if ( isToBeImported() ) {
|
||||
// isToBeImported() returns true for arrays.
|
||||
// Therefore, we need to check the top level type when creating the reference
|
||||
if ( isTopLevelTypeToBeImported() ) {
|
||||
return nameWithTopLevelTypeName != null ? nameWithTopLevelTypeName : name;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
if ( shouldUseSimpleName() ) {
|
||||
return name;
|
||||
}
|
||||
|
||||
@ -1566,16 +1579,16 @@ public class Type extends ModelElement implements Comparable<Type> {
|
||||
return trimmedClassName;
|
||||
}
|
||||
|
||||
private static String nameWithTopLevelTypeName(TypeElement element) {
|
||||
private static String nameWithTopLevelTypeName(TypeElement element, String name) {
|
||||
if ( element == null ) {
|
||||
return null;
|
||||
}
|
||||
if ( !element.getNestingKind().isNested() ) {
|
||||
return element.getSimpleName().toString();
|
||||
return name;
|
||||
}
|
||||
|
||||
Deque<CharSequence> elements = new ArrayDeque<>();
|
||||
elements.addFirst( element.getSimpleName() );
|
||||
elements.addFirst( name );
|
||||
Element parent = element.getEnclosingElement();
|
||||
while ( parent != null && parent.getKind() != ElementKind.PACKAGE ) {
|
||||
elements.addFirst( parent.getSimpleName() );
|
||||
|
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* 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._2880;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface Issue2880Mapper {
|
||||
|
||||
Target map(Source source);
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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._2880;
|
||||
|
||||
import org.mapstruct.ap.testutil.IssueKey;
|
||||
import org.mapstruct.ap.testutil.ProcessorTest;
|
||||
import org.mapstruct.ap.testutil.WithClasses;
|
||||
|
||||
@IssueKey("2880")
|
||||
@WithClasses({
|
||||
Issue2880Mapper.class,
|
||||
Outer.class,
|
||||
Source.class,
|
||||
Target.class,
|
||||
TargetData.class
|
||||
})
|
||||
public class Issue2880Test {
|
||||
|
||||
@ProcessorTest
|
||||
void shouldCompile() {
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* 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._2880;
|
||||
|
||||
public class Outer {
|
||||
|
||||
public static class SourceData {
|
||||
|
||||
// CHECKSTYLE:OFF
|
||||
public String value;
|
||||
// CHECKSTYLE:ON
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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._2880;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Source {
|
||||
|
||||
// CHECKSTYLE:OFF
|
||||
public Outer.SourceData[] data1;
|
||||
|
||||
public Outer.SourceData[] data2;
|
||||
|
||||
public List<Outer.SourceData> data3;
|
||||
|
||||
public List<Outer.SourceData> data4;
|
||||
// CHECKSTYLE:ON
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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._2880;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Target {
|
||||
|
||||
// CHECKSTYLE:OFF
|
||||
public TargetData[] data1;
|
||||
|
||||
public List<TargetData> data2;
|
||||
|
||||
public TargetData[] data3;
|
||||
|
||||
public List<TargetData> data4;
|
||||
// CHECKSTYLE:ON
|
||||
}
|
@ -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._2880;
|
||||
|
||||
public class TargetData {
|
||||
|
||||
// CHECKSTYLE:OFF
|
||||
public String value;
|
||||
// CHECKSTYLE:ON
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user