mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#999 make sure that the qualifiedName of the class is trimmed before doing any comparisons for import check
This commit is contained in:
parent
79f87e8833
commit
fc0f13a7a1
@ -36,7 +36,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.ConcurrentNavigableMap;
|
||||
import java.util.concurrent.ConcurrentSkipListMap;
|
||||
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.ElementKind;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
@ -444,16 +443,17 @@ public class TypeFactory {
|
||||
|
||||
private boolean isImported(String name, String qualifiedName) {
|
||||
String trimmedName = TypeFactory.trimSimpleClassName( name );
|
||||
String trimmedQualifiedName = TypeFactory.trimSimpleClassName( qualifiedName );
|
||||
String importedType = importedQualifiedTypesBySimpleName.get( trimmedName );
|
||||
|
||||
boolean imported = false;
|
||||
if ( importedType != null ) {
|
||||
if ( importedType.equals( qualifiedName ) ) {
|
||||
if ( importedType.equals( trimmedQualifiedName ) ) {
|
||||
imported = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
importedQualifiedTypesBySimpleName.put( trimmedName, qualifiedName );
|
||||
importedQualifiedTypesBySimpleName.put( trimmedName, trimmedQualifiedName );
|
||||
imported = true;
|
||||
}
|
||||
return imported;
|
||||
@ -530,6 +530,19 @@ public class TypeFactory {
|
||||
return typeMirror;
|
||||
}
|
||||
|
||||
/**
|
||||
* It strips the all the {@code []} from the {@code className}.
|
||||
*
|
||||
* E.g.
|
||||
* <pre>
|
||||
* trimSimpleClassName("String[][][]") -> "String"
|
||||
* trimSimpleClassName("String[]") -> "String"
|
||||
* </pre>
|
||||
*
|
||||
* @param className that needs to be trimmed
|
||||
*
|
||||
* @return the trimmed {@code className}, or {@code null} if the {@code className} was {@code null}
|
||||
*/
|
||||
static String trimSimpleClassName(String className) {
|
||||
if ( className == null ) {
|
||||
return null;
|
||||
|
@ -18,11 +18,10 @@
|
||||
*/
|
||||
package org.mapstruct.ap.test.array;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mapstruct.ap.test.array._target.ScientistDto;
|
||||
@ -30,12 +29,22 @@ import org.mapstruct.ap.test.array.source.Scientist;
|
||||
import org.mapstruct.ap.testutil.IssueKey;
|
||||
import org.mapstruct.ap.testutil.WithClasses;
|
||||
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
|
||||
import org.mapstruct.ap.testutil.runner.GeneratedSource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@WithClasses( { Scientist.class, ScientistDto.class, ScienceMapper.class } )
|
||||
@RunWith(AnnotationProcessorTestRunner.class)
|
||||
@IssueKey("108")
|
||||
public class ArrayMappingTest {
|
||||
|
||||
private final GeneratedSource generatedSource = new GeneratedSource();
|
||||
|
||||
@Rule
|
||||
public GeneratedSource getGeneratedSource() {
|
||||
return generatedSource;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCopyArraysInBean() {
|
||||
|
||||
@ -226,4 +235,9 @@ public class ArrayMappingTest {
|
||||
assertThat( existingTarget ).containsOnly( new long[] { 0L } );
|
||||
}
|
||||
|
||||
@Test
|
||||
@IssueKey( "999" )
|
||||
public void shouldNotContainFQNForStringArray() {
|
||||
getGeneratedSource().forMapper( ScienceMapper.class ).content().doesNotContain( "java.lang.String[]" );
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user