mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#3886: Records do not have property write accessors (apart from the record components)
This commit is contained in:
parent
f4d1818171
commit
c90c93630e
@ -286,6 +286,7 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<testRelease>${minimum.java.version}</testRelease>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.mapstruct.tools.gem</groupId>
|
||||
|
@ -796,6 +796,10 @@ public class Type extends ModelElement implements Comparable<Type> {
|
||||
* @return an unmodifiable map of all write accessors indexed by property name
|
||||
*/
|
||||
public Map<String, Accessor> getPropertyWriteAccessors( CollectionMappingStrategyGem cmStrategy ) {
|
||||
if ( isRecord() ) {
|
||||
// Records do not have setters, so we return an empty map
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
// collect all candidate target accessors
|
||||
List<Accessor> candidates = new ArrayList<>( getSetters() );
|
||||
candidates.addAll( getAlternativeTargetAccessors() );
|
||||
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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._3886.jdk21;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @author Filip Hrisafov
|
||||
*/
|
||||
@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR)
|
||||
public interface Issue3886Mapper {
|
||||
|
||||
RangeRecord map(LocalDate validFrom);
|
||||
|
||||
record RangeRecord(LocalDate validFrom) {
|
||||
|
||||
public RangeRecord restrictTo(RangeRecord other) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
// This method is here to ensure that MapStruct won't treat it as a setter
|
||||
}
|
||||
}
|
||||
}
|
@ -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._3886.jdk21;
|
||||
|
||||
import org.mapstruct.ap.testutil.IssueKey;
|
||||
import org.mapstruct.ap.testutil.ProcessorTest;
|
||||
import org.mapstruct.ap.testutil.WithClasses;
|
||||
import org.mapstruct.ap.testutil.runner.Compiler;
|
||||
|
||||
/**
|
||||
* @author Filip Hrisafov
|
||||
*/
|
||||
@WithClasses(Issue3886Mapper.class)
|
||||
@IssueKey("3886")
|
||||
class Issue3886Test {
|
||||
|
||||
// The current version of the Eclipse compiler we use does not support records
|
||||
@ProcessorTest(Compiler.JDK)
|
||||
void shouldCompile() {
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user