#3732 Do not generate obsolete imports for LocalDateTime <-> LocalDate conversion

This commit is contained in:
Filip Hrisafov 2024-11-09 10:15:33 +01:00
parent 21fdaa0f82
commit c2bd847599
3 changed files with 69 additions and 16 deletions

View File

@ -7,11 +7,8 @@ package org.mapstruct.ap.internal.conversion;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Set;
import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.ConversionContext;
import org.mapstruct.ap.internal.model.common.Type;
import org.mapstruct.ap.internal.util.Collections;
/** /**
* SimpleConversion for mapping {@link LocalDateTime} to * SimpleConversion for mapping {@link LocalDateTime} to
@ -25,22 +22,9 @@ public class JavaLocalDateTimeToLocalDateConversion extends SimpleConversion {
return "<SOURCE>.toLocalDate()"; return "<SOURCE>.toLocalDate()";
} }
@Override
protected Set<Type> getToConversionImportTypes(ConversionContext conversionContext) {
return Collections.asSet(
conversionContext.getTypeFactory().getType( LocalDate.class )
);
}
@Override @Override
protected String getFromExpression(ConversionContext conversionContext) { protected String getFromExpression(ConversionContext conversionContext) {
return "<SOURCE>.atStartOfDay()"; return "<SOURCE>.atStartOfDay()";
} }
@Override
protected Set<Type> getFromConversionImportTypes(ConversionContext conversionContext) {
return Collections.asSet(
conversionContext.getTypeFactory().getType( LocalDateTime.class )
);
}
} }

View File

@ -0,0 +1,47 @@
/*
* 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._3732;
import java.time.LocalDate;
import java.time.LocalDateTime;
import org.mapstruct.Mapper;
/**
* @author Filip Hrisafov
*/
@Mapper
public interface Issue3732Mapper {
Target map(Source source);
Source map(Target source);
class Source {
private LocalDateTime value;
public LocalDateTime getValue() {
return value;
}
public void setValue(LocalDateTime value) {
this.value = value;
}
}
class Target {
private LocalDate value;
public LocalDate getValue() {
return value;
}
public void setValue(LocalDate value) {
this.value = value;
}
}
}

View File

@ -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._3732;
import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses;
/**
* @author Filip Hrisafov
*/
@IssueKey("3732")
@WithClasses({ Issue3732Mapper.class })
class Issue3732Test {
@ProcessorTest
void shouldGenerateCorrectMapper() {
}
}