Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -1682,53 +1682,19 @@ private void reportErrorForUnmappedTargetPropertiesIfRequired() {
}
else if ( !unprocessedTargetProperties.isEmpty() && unmappedTargetPolicy.requiresReport() ) {

if ( !( method instanceof ForgedMethod ) ) {
Message msg = unmappedTargetPolicy.getDiagnosticKind() == Diagnostic.Kind.ERROR ?
Message.BEANMAPPING_UNMAPPED_TARGETS_ERROR : Message.BEANMAPPING_UNMAPPED_TARGETS_WARNING;
Object[] args = new Object[] {
MessageFormat.format(
"{0,choice,1#property|1<properties}: \"{1}\"",
unprocessedTargetProperties.size(),
Strings.join( unprocessedTargetProperties.keySet(), ", " )
)
};
Message unmappedPropertiesMsg =
unmappedTargetPolicy.getDiagnosticKind() == Diagnostic.Kind.ERROR ?
Message.BEANMAPPING_UNMAPPED_TARGETS_ERROR :
Message.BEANMAPPING_UNMAPPED_TARGETS_WARNING;
Message unmappedForgedPropertiesMsg =
unmappedTargetPolicy.getDiagnosticKind() == Diagnostic.Kind.ERROR ?
Message.BEANMAPPING_UNMAPPED_FORGED_TARGETS_ERROR :
Message.BEANMAPPING_UNMAPPED_FORGED_TARGETS_WARNING;
Comment thread
Zegveld marked this conversation as resolved.
Outdated

ctx.getMessager().printMessage(
method.getExecutable(),
msg,
args
);
}
else if ( !ctx.isErroneous() ) {
Message msg = unmappedTargetPolicy.getDiagnosticKind() == Diagnostic.Kind.ERROR ?
Message.BEANMAPPING_UNMAPPED_FORGED_TARGETS_ERROR :
Message.BEANMAPPING_UNMAPPED_FORGED_TARGETS_WARNING;
String sourceErrorMessage = method.getParameters().get( 0 ).getType().describe();
String targetErrorMessage = method.getReturnType().describe();
if ( ( (ForgedMethod) method ).getHistory() != null ) {
ForgedMethodHistory history = ( (ForgedMethod) method ).getHistory();
sourceErrorMessage = history.createSourcePropertyErrorMessage();
targetErrorMessage = MessageFormat.format(
"\"{0} {1}\"",
history.getTargetType().describe(),
history.createTargetPropertyName()
);
}
Object[] args = new Object[] {
MessageFormat.format(
"{0,choice,1#property|1<properties}: \"{1}\"",
unprocessedTargetProperties.size(),
Strings.join( unprocessedTargetProperties.keySet(), ", " )
),
sourceErrorMessage,
targetErrorMessage
};
ctx.getMessager().printMessage(
method.getExecutable(),
msg,
args
);
}
reportErrorForUnmappedProperties(
unprocessedTargetProperties,
unmappedPropertiesMsg,
unmappedForgedPropertiesMsg );

}
}
Expand All @@ -1746,22 +1712,65 @@ private ReportingPolicyGem getUnmappedSourcePolicy() {

private void reportErrorForUnmappedSourcePropertiesIfRequired() {
ReportingPolicyGem unmappedSourcePolicy = getUnmappedSourcePolicy();

if ( !unprocessedSourceProperties.isEmpty() && unmappedSourcePolicy.requiresReport() ) {

Message msg = unmappedSourcePolicy.getDiagnosticKind() == Diagnostic.Kind.ERROR ?
Message.BEANMAPPING_UNMAPPED_SOURCES_ERROR : Message.BEANMAPPING_UNMAPPED_SOURCES_WARNING;
Message unmappedPropertiesMsg =
unmappedSourcePolicy.getDiagnosticKind() == Diagnostic.Kind.ERROR ?
Message.BEANMAPPING_UNMAPPED_SOURCES_ERROR :
Message.BEANMAPPING_UNMAPPED_SOURCES_WARNING;
Message unmappedForgedPropertiesMsg =
unmappedSourcePolicy.getDiagnosticKind() == Diagnostic.Kind.ERROR ?
Message.BEANMAPPING_UNMAPPED_FORGED_SOURCES_ERROR :
Message.BEANMAPPING_UNMAPPED_FORGED_SOURCES_WARNING;
Comment thread
Zegveld marked this conversation as resolved.
Outdated

reportErrorForUnmappedProperties(
unprocessedSourceProperties,
unmappedPropertiesMsg,
unmappedForgedPropertiesMsg );
}
}

private void reportErrorForUnmappedProperties(Map<String, Accessor> unmappedProperties,
Message unmappedPropertiesMsg,
Message unmappedForgedPropertiesMsg) {
if ( !( method instanceof ForgedMethod ) ) {
Object[] args = new Object[] {
MessageFormat.format(
"{0,choice,1#property|1<properties}: \"{1}\"",
unprocessedSourceProperties.size(),
Strings.join( unprocessedSourceProperties.keySet(), ", " )
unmappedProperties.size(),
Strings.join( unmappedProperties.keySet(), ", " )
)
};

ctx.getMessager().printMessage(
method.getExecutable(),
msg,
unmappedPropertiesMsg,
args
);
}
else if ( !ctx.isErroneous() ) {
String sourceErrorMessage = method.getParameters().get( 0 ).getType().describe();
String targetErrorMessage = method.getReturnType().describe();
if ( ( (ForgedMethod) method ).getHistory() != null ) {
ForgedMethodHistory history = ( (ForgedMethod) method ).getHistory();
sourceErrorMessage = history.createSourcePropertyErrorMessage();
targetErrorMessage = MessageFormat.format(
"\"{0} {1}\"",
history.getTargetType().describe(),
history.createTargetPropertyName()
);
}
Object[] args = new Object[] {
MessageFormat.format(
"{0,choice,1#property|1<properties}: \"{1}\"",
unmappedProperties.size(),
Strings.join( unmappedProperties.keySet(), ", " )
),
sourceErrorMessage,
targetErrorMessage
};
ctx.getMessager().printMessage(
method.getExecutable(),
unmappedForgedPropertiesMsg,
args
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public enum Message {
BEANMAPPING_UNMAPPED_FORGED_TARGETS_ERROR( "Unmapped target %s. Mapping from %s to %s." ),
BEANMAPPING_UNMAPPED_SOURCES_WARNING( "Unmapped source %s.", Diagnostic.Kind.WARNING ),
BEANMAPPING_UNMAPPED_SOURCES_ERROR( "Unmapped source %s." ),
BEANMAPPING_UNMAPPED_FORGED_SOURCES_WARNING( "Unmapped source %s. Mapping from %s to %s.", Diagnostic.Kind.WARNING ),
BEANMAPPING_UNMAPPED_FORGED_SOURCES_ERROR( "Unmapped source %s. Mapping from %s to %s." ),
BEANMAPPING_MISSING_IGNORED_SOURCES_ERROR( "Ignored unknown source %s." ),
BEANMAPPING_CYCLE_BETWEEN_PROPERTIES( "Cycle(s) between properties given via dependsOn(): %s." ),
BEANMAPPING_UNKNOWN_PROPERTY_IN_DEPENDS_ON( "\"%s\" is no property of the method return type." ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@

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

/**
*
* @author Sjaak Derksen
*/
@Mapper
@Mapper(unmappedSourcePolicy = ReportingPolicy.WARN)
Comment thread
filiphr marked this conversation as resolved.
Outdated
public abstract class AbstractSourceTargetMapperPrivate extends SourceTargetmapperPrivateBase {

public static final AbstractSourceTargetMapperPrivate INSTANCE =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@

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

/**
*
* @author Sjaak Derksen
*/
@Mapper
@Mapper(unmappedSourcePolicy = ReportingPolicy.WARN)
Comment thread
filiphr marked this conversation as resolved.
Outdated
public abstract class AbstractSourceTargetMapperProtected extends SourceTargetmapperProtectedBase {

public static final AbstractSourceTargetMapperProtected INSTANCE =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* @author Sjaak Derksen
*/
@WithClasses( { Source.class, Target.class, ReferencedSource.class, ReferencedTarget.class } )
@IssueKey("2788")
Comment thread
filiphr marked this conversation as resolved.
Outdated
public class ReferencedAccessibilityTest {

@RegisterExtension
Expand All @@ -34,8 +35,13 @@ public class ReferencedAccessibilityTest {
diagnostics = {
@Diagnostic(type = SourceTargetMapperPrivate.class,
kind = javax.tools.Diagnostic.Kind.WARNING,
line = 22,
line = 23,
message = "Unmapped target property: \"bar\". Mapping from property " +
"\"ReferencedSource referencedSource\" to \"ReferencedTarget referencedTarget\"."),
@Diagnostic(type = SourceTargetMapperPrivate.class,
kind = javax.tools.Diagnostic.Kind.WARNING,
line = 23,
message = "Unmapped source property: \"foo\". Mapping from property " +
"\"ReferencedSource referencedSource\" to \"ReferencedTarget referencedTarget\".")
}
)
Expand All @@ -61,8 +67,13 @@ public void shouldBeAbleToAccessProtectedMethodInReferencedInSamePackage() { }
diagnostics = {
@Diagnostic(type = SourceTargetMapperDefaultOther.class,
kind = javax.tools.Diagnostic.Kind.WARNING,
line = 24,
line = 25,
message = "Unmapped target property: \"bar\". Mapping " +
"from property \"ReferencedSource referencedSource\" to \"ReferencedTarget referencedTarget\"."),
@Diagnostic(type = SourceTargetMapperDefaultOther.class,
kind = javax.tools.Diagnostic.Kind.WARNING,
line = 25,
message = "Unmapped source property: \"foo\". Mapping " +
"from property \"ReferencedSource referencedSource\" to \"ReferencedTarget referencedTarget\".")
}
)
Expand All @@ -83,8 +94,13 @@ public void shouldBeAbleToAccessProtectedMethodInBase() { }
diagnostics = {
@Diagnostic(type = AbstractSourceTargetMapperPrivate.class,
kind = javax.tools.Diagnostic.Kind.WARNING,
line = 23,
line = 24,
message = "Unmapped target property: \"bar\". Mapping from property " +
"\"ReferencedSource referencedSource\" to \"ReferencedTarget referencedTarget\"."),
@Diagnostic(type = AbstractSourceTargetMapperPrivate.class,
kind = javax.tools.Diagnostic.Kind.WARNING,
line = 24,
message = "Unmapped source property: \"foo\". Mapping from property " +
"\"ReferencedSource referencedSource\" to \"ReferencedTarget referencedTarget\".")
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.ap.test.accessibility.referenced.a.ReferencedMapperDefaultOther;
import org.mapstruct.factory.Mappers;

/**
*
* @author Sjaak Derksen
*/
@Mapper(uses = ReferencedMapperDefaultOther.class)
@Mapper(uses = ReferencedMapperDefaultOther.class, unmappedSourcePolicy = ReportingPolicy.WARN)
Comment thread
filiphr marked this conversation as resolved.
Outdated
public interface SourceTargetMapperDefaultOther {

SourceTargetMapperDefaultOther INSTANCE =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@

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

/**
*
* @author Sjaak Derksen
*/
@Mapper(uses = ReferencedMapperDefaultSame.class)
@Mapper(uses = ReferencedMapperDefaultSame.class, unmappedSourcePolicy = ReportingPolicy.WARN)
Comment thread
filiphr marked this conversation as resolved.
Outdated
public interface SourceTargetMapperDefaultSame {

SourceTargetMapperDefaultSame INSTANCE = Mappers.getMapper( SourceTargetMapperDefaultSame.class );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@

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

/**
*
* @author Sjaak Derksen
*/
@Mapper(uses = ReferencedMapperPrivate.class)
@Mapper(uses = ReferencedMapperPrivate.class, unmappedSourcePolicy = ReportingPolicy.WARN)
Comment thread
filiphr marked this conversation as resolved.
Outdated
public interface SourceTargetMapperPrivate {

SourceTargetMapperPrivate INSTANCE = Mappers.getMapper( SourceTargetMapperPrivate.class );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@

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

/**
*
* @author Sjaak Derksen
*/
@Mapper(uses = ReferencedMapperProtected.class)
@Mapper(uses = ReferencedMapperProtected.class, unmappedSourcePolicy = ReportingPolicy.WARN)
Comment thread
filiphr marked this conversation as resolved.
Outdated
public interface SourceTargetMapperProtected {

SourceTargetMapperProtected INSTANCE = Mappers.getMapper( SourceTargetMapperProtected.class );
Expand Down