Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -571,11 +571,6 @@ private boolean checkParameterAndReturnType(ExecutableElement method, List<Param
return false;
}

if ( parameterType.isPrimitive() ) {
messager.printMessage( method, Message.RETRIEVAL_PRIMITIVE_PARAMETER );
return false;
}

for ( Type typeParameter : parameterType.getTypeParameters() ) {
if ( typeParameter.hasSuperBound() ) {
messager.printMessage( method, Message.RETRIEVAL_WILDCARD_SUPER_BOUND_SOURCE );
Expand Down
Original file line number Diff line number Diff line change
@@ -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._3943;

import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;

@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR)
public interface Issue3943ErroneousMapper {

Issue3943ErroneousMapper INSTANCE = Mappers.getMapper( Issue3943ErroneousMapper.class );

Target map(int somethingElse);

class Target {

private final int value;

public Target(int value) {
this.value = value;
}

public int getValue() {
return value;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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._3943;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

@Mapper
public interface Issue3943Mapper {

Issue3943Mapper INSTANCE = Mappers.getMapper( Issue3943Mapper.class );

TargetWithMatchingProperty mapImplicitly(int value);

@Mapping(target = "value", source = "value")
TargetWithMatchingProperty mapWithMatchingProperty(int value);

@Mapping(target = "nonMatchingProperty", source = "value")
TargetWithoutMatchingProperty mapWithoutMatchingProperty(int value);

class TargetWithMatchingProperty {

private final int value;

public TargetWithMatchingProperty(int value) {
this.value = value;
}

public int getValue() {
return value;
}
}

class TargetWithoutMatchingProperty {

private final int nonMatchingProperty;

public TargetWithoutMatchingProperty(int nonMatchingProperty) {
this.nonMatchingProperty = nonMatchingProperty;
}

public int getNonMatchingProperty() {
return nonMatchingProperty;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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._3943;

import javax.tools.Diagnostic.Kind;

import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;

import static org.assertj.core.api.Assertions.assertThat;

@IssueKey("3943")
@WithClasses(Issue3943Mapper.class)
class Issue3943Test {

@ProcessorTest
void shouldGenerateValidCodeForBeanWhenMappingImplicitly() {
Issue3943Mapper.TargetWithMatchingProperty target = Issue3943Mapper.INSTANCE.mapImplicitly( 42 );
assertThat( target ).isNotNull();
assertThat( target.getValue() ).isEqualTo( 42L );
}

@ProcessorTest
void shouldGenerateValidCodeForBeanWithMatchingProperty() {
Issue3943Mapper.TargetWithMatchingProperty target = Issue3943Mapper.INSTANCE.mapWithMatchingProperty( 42 );
assertThat( target ).isNotNull();
assertThat( target.getValue() ).isEqualTo( 42L );
}

@ProcessorTest
void shouldGenerateValidCodeForBeanWithoutMatchingProperty() {
Issue3943Mapper.TargetWithoutMatchingProperty target =
Issue3943Mapper.INSTANCE.mapWithoutMatchingProperty( 42 );
assertThat( target ).isNotNull();
assertThat( target.getNonMatchingProperty() ).isEqualTo( 42L );
}

@ProcessorTest
@WithClasses( { Issue3943ErroneousMapper.class } )
@ExpectedCompilationOutcome(
value = CompilationResult.FAILED,
diagnostics = {
@Diagnostic(type = Issue3943ErroneousMapper.class,
kind = Kind.ERROR,
line = 16,
alternativeLine = 17,
message = "Unmapped target property: \"value\"." )
}
)
void shouldFailToGenerateCodeIfPropertyNameDoesNotMatch() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,5 @@ public interface ErroneousMapper {

long sourceToLong(Source source);

Source longToSource(long id);

Target sourceToTargetWithMappingTargetType(Source source, @TargetType Class<?> clazz);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ public class ErroneousMappingsTest {
@Diagnostic(type = ErroneousMapper.class,
kind = Kind.ERROR,
line = 20,
message = "Can't generate mapping method with primitive parameter type."),
@Diagnostic(type = ErroneousMapper.class,
kind = Kind.ERROR,
line = 22,
message =
"Can't generate mapping method that has a parameter annotated with @TargetType.")
}
Expand Down