From 7041361b76fbcadb4da3c35fc8fcb9f8ad32a6b8 Mon Sep 17 00:00:00 2001 From: Gunnar Morling Date: Wed, 5 Nov 2014 19:31:51 +0100 Subject: [PATCH] #65 Removing FactoryMethod interface --- .../mapstruct/ap/model/AssignmentFactory.java | 8 +++-- .../mapstruct/ap/model/BeanMappingMethod.java | 27 +++++++-------- .../org/mapstruct/ap/model/FactoryMethod.java | 33 ------------------- .../ap/model/IterableMappingMethod.java | 9 ++--- .../mapstruct/ap/model/MapMappingMethod.java | 10 +++--- .../mapstruct/ap/model/MethodReference.java | 10 +++--- 6 files changed, 32 insertions(+), 65 deletions(-) delete mode 100644 processor/src/main/java/org/mapstruct/ap/model/FactoryMethod.java diff --git a/processor/src/main/java/org/mapstruct/ap/model/AssignmentFactory.java b/processor/src/main/java/org/mapstruct/ap/model/AssignmentFactory.java index 719add3e0..f4c1444c1 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/AssignmentFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/model/AssignmentFactory.java @@ -18,10 +18,12 @@ */ package org.mapstruct.ap.model; -import org.mapstruct.ap.model.assignment.Assignment; import java.util.List; import java.util.Set; + import javax.tools.Diagnostic; + +import org.mapstruct.ap.model.assignment.Assignment; import org.mapstruct.ap.model.common.ConversionContext; import org.mapstruct.ap.model.common.Type; import org.mapstruct.ap.model.source.Method; @@ -56,8 +58,8 @@ public class AssignmentFactory { return new Direct( sourceRef ); } - public static FactoryMethod createFactoryMethod( Type returnType, MappingBuilderContext ctx ) { - FactoryMethod result = null; + public static MethodReference createFactoryMethod( Type returnType, MappingBuilderContext ctx ) { + MethodReference result = null; for ( SourceMethod method : ctx.getSourceModel() ) { if ( !method.overridesMethod() && !method.isIterableMapping() && !method.isMapMapping() && method.getSourceParameters().isEmpty() ) { diff --git a/processor/src/main/java/org/mapstruct/ap/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/model/BeanMappingMethod.java index 32b9fe8f2..909d37002 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/model/BeanMappingMethod.java @@ -26,28 +26,28 @@ import java.util.HashSet; import java.util.List; 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.ap.model.PropertyMapping.ConstantMappingBuilder; +import org.mapstruct.ap.model.PropertyMapping.JavaExpressionMappingBuilder; +import org.mapstruct.ap.model.PropertyMapping.PropertyMappingBuilder; import org.mapstruct.ap.model.common.Parameter; import org.mapstruct.ap.model.common.Type; import org.mapstruct.ap.model.source.Mapping; import org.mapstruct.ap.model.source.SourceMethod; +import org.mapstruct.ap.model.source.SourceReference; import org.mapstruct.ap.option.ReportingPolicy; import org.mapstruct.ap.util.Executables; import org.mapstruct.ap.util.MapperConfig; import org.mapstruct.ap.util.Strings; -import org.mapstruct.ap.model.PropertyMapping.PropertyMappingBuilder; -import org.mapstruct.ap.model.PropertyMapping.ConstantMappingBuilder; -import org.mapstruct.ap.model.PropertyMapping.JavaExpressionMappingBuilder; -import org.mapstruct.ap.model.source.SourceReference; - /** * A {@link MappingMethod} implemented by a {@link Mapper} class which maps one - bean sourceParameter to another, optionally configured by one or more - {@link PropertyMapping}s. + * bean sourceParameter to another, optionally configured by one or more + * {@link PropertyMapping}s. * * @author Gunnar Morling */ @@ -56,10 +56,7 @@ public class BeanMappingMethod extends MappingMethod { private final List propertyMappings; private final Map> mappingsByParameter; private final List constantMappings; - - - private final FactoryMethod factoryMethod; - + private final MethodReference factoryMethod; public static class Builder { @@ -98,11 +95,10 @@ public class BeanMappingMethod extends MappingMethod { reportErrorForUnmappedTargetPropertiesIfRequired( ); - FactoryMethod factoryMethod = AssignmentFactory.createFactoryMethod( method.getReturnType(), ctx ); + MethodReference factoryMethod = AssignmentFactory.createFactoryMethod( method.getReturnType(), ctx ); return new BeanMappingMethod( method, propertyMappings, factoryMethod ); } - /** * This method builds the list of target accessors. */ @@ -384,12 +380,11 @@ public class BeanMappingMethod extends MappingMethod { ); } } - } private BeanMappingMethod(SourceMethod method, List propertyMappings, - FactoryMethod factoryMethod) { + MethodReference factoryMethod) { super( method ); this.propertyMappings = propertyMappings; @@ -434,7 +429,7 @@ public class BeanMappingMethod extends MappingMethod { return types; } - public FactoryMethod getFactoryMethod() { + public MethodReference getFactoryMethod() { return this.factoryMethod; } diff --git a/processor/src/main/java/org/mapstruct/ap/model/FactoryMethod.java b/processor/src/main/java/org/mapstruct/ap/model/FactoryMethod.java deleted file mode 100644 index 307d892b0..000000000 --- a/processor/src/main/java/org/mapstruct/ap/model/FactoryMethod.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.mapstruct.ap.model; - -import java.util.List; -import org.mapstruct.ap.model.common.Type; - -/** - * FactoryMethod, implemented in referenced mapper. - * - * @author Sjaak Derksen - */ -public interface FactoryMethod { - - List getExceptionTypes(); - -} diff --git a/processor/src/main/java/org/mapstruct/ap/model/IterableMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/model/IterableMappingMethod.java index 51a0fa31c..9685a525f 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/IterableMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/model/IterableMappingMethod.java @@ -20,6 +20,7 @@ package org.mapstruct.ap.model; import java.util.List; import java.util.Set; + import javax.lang.model.type.TypeMirror; import javax.tools.Diagnostic; @@ -39,7 +40,7 @@ import org.mapstruct.ap.util.Strings; public class IterableMappingMethod extends MappingMethod { private final Assignment elementAssignment; - private final FactoryMethod factoryMethod; + private final MethodReference factoryMethod; private final boolean overridden; public static class Builder { @@ -101,13 +102,13 @@ public class IterableMappingMethod extends MappingMethod { // target accessor is setter, so decorate assignment as setter assignment = new SetterWrapper( assignment, method.getThrownTypes() ); - FactoryMethod factoryMethod = AssignmentFactory.createFactoryMethod( method.getReturnType(), ctx ); + MethodReference factoryMethod = AssignmentFactory.createFactoryMethod( method.getReturnType(), ctx ); return new IterableMappingMethod( method, assignment, factoryMethod ); } } - private IterableMappingMethod(Method method, Assignment parameterAssignment, FactoryMethod factoryMethod) { + private IterableMappingMethod(Method method, Assignment parameterAssignment, MethodReference factoryMethod) { super( method ); this.elementAssignment = parameterAssignment; this.factoryMethod = factoryMethod; @@ -146,7 +147,7 @@ public class IterableMappingMethod extends MappingMethod { ); } - public FactoryMethod getFactoryMethod() { + public MethodReference getFactoryMethod() { return this.factoryMethod; } diff --git a/processor/src/main/java/org/mapstruct/ap/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/model/MapMappingMethod.java index 1fd2389d6..b2cc0a952 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/model/MapMappingMethod.java @@ -20,6 +20,7 @@ package org.mapstruct.ap.model; import java.util.List; import java.util.Set; + import javax.lang.model.type.TypeMirror; import javax.tools.Diagnostic; @@ -40,7 +41,7 @@ public class MapMappingMethod extends MappingMethod { private final Assignment keyAssignment; private final Assignment valueAssignment; - private final FactoryMethod factoryMethod; + private final MethodReference factoryMethod; private final boolean overridden; public static class Builder { @@ -133,18 +134,17 @@ public class MapMappingMethod extends MappingMethod { ctx.getMessager().printMessage( Diagnostic.Kind.ERROR, message, method.getExecutable() ); } - FactoryMethod factoryMethod = AssignmentFactory.createFactoryMethod( method.getReturnType(), ctx ); + MethodReference factoryMethod = AssignmentFactory.createFactoryMethod( method.getReturnType(), ctx ); keyAssignment = new LocalVarWrapper( keyAssignment, method.getThrownTypes() ); valueAssignment = new LocalVarWrapper( valueAssignment, method.getThrownTypes() ); return new MapMappingMethod( method, keyAssignment, valueAssignment, factoryMethod ); } - } private MapMappingMethod(Method method, Assignment keyAssignment, Assignment valueAssignment, - FactoryMethod factoryMethod) { + MethodReference factoryMethod) { super( method ); this.keyAssignment = keyAssignment; @@ -206,7 +206,7 @@ public class MapMappingMethod extends MappingMethod { ); } - public FactoryMethod getFactoryMethod() { + public MethodReference getFactoryMethod() { return this.factoryMethod; } diff --git a/processor/src/main/java/org/mapstruct/ap/model/MethodReference.java b/processor/src/main/java/org/mapstruct/ap/model/MethodReference.java index 179ca5e0f..67ef37f3c 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/MethodReference.java +++ b/processor/src/main/java/org/mapstruct/ap/model/MethodReference.java @@ -18,12 +18,13 @@ */ package org.mapstruct.ap.model; -import org.mapstruct.ap.model.assignment.Assignment; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; + +import org.mapstruct.ap.model.assignment.Assignment; import org.mapstruct.ap.model.common.ConversionContext; import org.mapstruct.ap.model.common.Parameter; import org.mapstruct.ap.model.common.Type; @@ -31,11 +32,12 @@ import org.mapstruct.ap.model.source.Method; import org.mapstruct.ap.model.source.builtin.BuiltInMethod; /** - * Represents a reference to {@link MappingMethod}. + * Represents a reference to another method, e.g. used to map a bean property from source to target type or to + * instantiate the return value of a mapping method (rather than calling the {@code new} operator). * * @author Gunnar Morling */ -public class MethodReference extends MappingMethod implements Assignment, FactoryMethod { +public class MethodReference extends MappingMethod implements Assignment { private final MapperReference declaringMapper; private final Set importTypes; @@ -54,7 +56,7 @@ public class MethodReference extends MappingMethod implements Assignment, Factor * {@code JAXBElement} to {@code Foo} to for which a nested method call will be generated: * {@code setFoo(barToFoo( jaxbElemToValue( bar) ) )} * - * If there's no nested typeConversion or other mapping method, this will be a {@link Simple} assignment. + * If there's no nested typeConversion or other mapping method, this will be a {@link Direct} assignment. */ private Assignment assignment;