This commit is contained in:
Gunnar Morling 2014-10-12 18:24:17 +02:00
parent 9adbb423c6
commit a5dc5d78ab
5 changed files with 282 additions and 264 deletions

View File

@ -27,8 +27,8 @@ import java.util.Map;
import java.util.Set;
import javax.lang.model.element.ExecutableElement;
import javax.tools.Diagnostic;
import org.mapstruct.CollectionMappingStrategy;
import org.mapstruct.CollectionMappingStrategy;
import org.mapstruct.ap.model.common.Parameter;
import org.mapstruct.ap.model.common.Type;
import org.mapstruct.ap.model.source.Mapping;

View File

@ -18,11 +18,12 @@
*/
package org.mapstruct.ap.model;
import org.mapstruct.ap.model.assignment.Assignment;
import java.util.List;
import java.util.Set;
import javax.lang.model.type.TypeMirror;
import javax.tools.Diagnostic;
import org.mapstruct.ap.model.assignment.Assignment;
import org.mapstruct.ap.model.assignment.SetterWrapper;
import org.mapstruct.ap.model.common.Parameter;
import org.mapstruct.ap.model.common.Type;
@ -77,7 +78,8 @@ public class IterableMappingMethod extends MappingMethod {
Strings.getSaveVariableName( sourceElementType.getName(), method.getParameterNames() );
Assignment assignment = ctx.getMappingResolver().getTargetAssignment( method,
Assignment assignment = ctx.getMappingResolver().getTargetAssignment(
method,
"collection element",
sourceElementType,
targetElementType,

View File

@ -18,11 +18,12 @@
*/
package org.mapstruct.ap.model;
import org.mapstruct.ap.model.assignment.Assignment;
import java.util.List;
import java.util.Set;
import javax.lang.model.type.TypeMirror;
import javax.tools.Diagnostic;
import org.mapstruct.ap.model.assignment.Assignment;
import org.mapstruct.ap.model.assignment.LocalVarWrapper;
import org.mapstruct.ap.model.common.Parameter;
import org.mapstruct.ap.model.common.Type;
@ -90,7 +91,8 @@ public class MapMappingMethod extends MappingMethod {
Type keySourceType = sourceTypeParams.get( 0 );
Type keyTargetType = resultTypeParams.get( 0 );
Assignment keyAssignment = ctx.getMappingResolver().getTargetAssignment( method,
Assignment keyAssignment = ctx.getMappingResolver().getTargetAssignment(
method,
"map key",
keySourceType,
keyTargetType,
@ -101,8 +103,10 @@ public class MapMappingMethod extends MappingMethod {
);
if ( keyAssignment == null ) {
String message = String.format( "Can't create implementation of method %s. Found no method nor "
+ "built-in conversion for mapping source key type to target key type.", method );
String message = String.format(
"Can't create implementation of method %s. Found no method nor "
+ "built-in conversion for mapping source key type to target key type.", method
);
method.printMessage( ctx.getMessager(), Diagnostic.Kind.ERROR, message );
}
@ -110,7 +114,8 @@ public class MapMappingMethod extends MappingMethod {
Type valueSourceType = sourceTypeParams.get( 1 );
Type valueTargetType = resultTypeParams.get( 1 );
Assignment valueAssignment = ctx.getMappingResolver().getTargetAssignment( method,
Assignment valueAssignment = ctx.getMappingResolver().getTargetAssignment(
method,
"map value",
valueSourceType,
valueTargetType,
@ -121,8 +126,10 @@ public class MapMappingMethod extends MappingMethod {
);
if ( valueAssignment == null ) {
String message = String.format( "Can't create implementation of method %s. Found no method nor "
+ "built-in conversion for mapping source value type to target value type.", method );
String message = String.format(
"Can't create implementation of method %s. Found no method nor "
+ "built-in conversion for mapping source value type to target value type.", method
);
method.printMessage( ctx.getMessager(), Diagnostic.Kind.ERROR, message );
}

View File

@ -25,7 +25,6 @@ import java.util.List;
import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;
import javax.annotation.processing.Messager;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
@ -88,7 +87,14 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
typeUtils,
messager,
options,
new MappingResolverImpl( context.getMessager(), elementUtils, typeUtils, typeFactory, sourceModel, mapperReferences ),
new MappingResolverImpl(
context.getMessager(),
elementUtils,
typeUtils,
typeFactory,
sourceModel,
mapperReferences
),
mapperTypeElement,
sourceModel,
mapperReferences

View File

@ -22,7 +22,6 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.annotation.processing.Messager;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Elements;
@ -74,7 +73,8 @@ public class MappingResolverImpl implements MappingResolver {
*/
private final Set<VirtualMappingMethod> usedVirtualMappings = new HashSet<VirtualMappingMethod>();
public MappingResolverImpl(Messager messager, Elements elementUtils, Types typeUtils, TypeFactory typeFactory, List<SourceMethod> sourceModel, List<MapperReference> mapperReferences) {
public MappingResolverImpl(Messager messager, Elements elementUtils, Types typeUtils, TypeFactory typeFactory,
List<SourceMethod> sourceModel, List<MapperReference> mapperReferences) {
this.messager = messager;
this.typeUtils = typeUtils;
this.typeFactory = typeFactory;
@ -122,7 +122,8 @@ public class MappingResolverImpl implements MappingResolver {
List<TypeMirror> qualifiers,
String sourceReference) {
ResolvingAttempt attempt = new ResolvingAttempt( sourceModel,
ResolvingAttempt attempt = new ResolvingAttempt(
sourceModel,
mapperReferences,
mappingMethod,
mappedElement,
@ -236,7 +237,6 @@ public class MappingResolverImpl implements MappingResolver {
/**
* Returns a reference to a method mapping the given source type to the given target type, if such a method
* exists.
*
*/
private Assignment resolveViaMethod(Type sourceType, Type targetType) {
@ -288,8 +288,10 @@ public class MappingResolverImpl implements MappingResolver {
// a nested method call can be called. so C = methodY( methodX (A) )
for ( Method methodYCandidate : methodYCandidates ) {
if ( methodYCandidate.getSourceParameters().size() == 1 ) {
methodRefY = resolveViaMethod( methodYCandidate.getSourceParameters().get( 0 ).getType(),
targetType );
methodRefY = resolveViaMethod(
methodYCandidate.getSourceParameters().get( 0 ).getType(),
targetType
);
if ( methodRefY != null ) {
Assignment methodRefX = resolveViaMethod(
sourceType,
@ -412,7 +414,8 @@ public class MappingResolverImpl implements MappingResolver {
"Ambiguous mapping methods found for mapping " + mappedElement + " from %s to %s: %s.",
sourceType,
returnType,
Strings.join( candidates, ", " ) );
Strings.join( candidates, ", " )
);
mappingMethod.printMessage( messager, Kind.ERROR, errorMsg );
}