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 3e2944ff2..59ef946af 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/model/BeanMappingMethod.java @@ -38,9 +38,9 @@ import org.mapstruct.ap.model.source.Method; public class BeanMappingMethod extends MappingMethod { private final List propertyMappings; - private final FactoryMethod factoryMethod; + private final MethodReference factoryMethod; - public BeanMappingMethod(Method method, List propertyMappings, FactoryMethod factoryMethod) { + public BeanMappingMethod(Method method, List propertyMappings, MethodReference factoryMethod) { super( method ); this.propertyMappings = propertyMappings; this.factoryMethod = factoryMethod; @@ -76,7 +76,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 f949336a4..000000000 --- a/processor/src/main/java/org/mapstruct/ap/model/FactoryMethod.java +++ /dev/null @@ -1,81 +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.HashSet; -import java.util.Set; - -import org.mapstruct.ap.model.source.Method; -import org.mapstruct.ap.model.common.Type; -import org.mapstruct.ap.model.common.ModelElement; - -/** - * A factory method - * - * @author Sjaak Derksen - */ -public class FactoryMethod extends ModelElement { - - private final String name; - private final boolean hasDeclaringMapper; - private final MapperReference declaringMapper; - private final Type returnType; - - public FactoryMethod( Method method, MapperReference declaringMapper ) { - this.name = method.getName(); - this.hasDeclaringMapper = method.getDeclaringMapper() != null; - this.declaringMapper = declaringMapper; - this.returnType = method.getReturnType(); - } - - public String getName() { - return name; - } - - public Type getDeclaringMapper() { - return declaringMapper.getMapperType(); - } - - public String getMapperVariableName() { - return declaringMapper.getVariableName(); - } - - @Override - public Set getImportTypes() { - Set types = new HashSet(); - types.add( returnType ); - types.addAll( returnType.getImportTypes() ); - return types; - } - - /** - * There is no declaring mapper when the factory method is on an abstract - * mapper class. If the declaring mapper is a referenced mapper, then this will - * result into true. - * - * @return true when declaring mapper is a referenced mapper (or factory) - */ - public boolean isHasDeclaringMapper() { - return hasDeclaringMapper; - } - - public Object getReturnType() { - return returnType; - } -} diff --git a/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java index b42b6f348..175c34b7d 100644 --- a/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java @@ -45,7 +45,6 @@ import org.mapstruct.ap.conversion.Conversions; import org.mapstruct.ap.conversion.DefaultConversionContext; import org.mapstruct.ap.model.BeanMappingMethod; import org.mapstruct.ap.model.DefaultMapperReference; -import org.mapstruct.ap.model.FactoryMethod; import org.mapstruct.ap.model.IterableMappingMethod; import org.mapstruct.ap.model.MapMappingMethod; import org.mapstruct.ap.model.Mapper; @@ -209,9 +208,9 @@ public class MapperCreationProcessor implements ModelElementProcessor mapperReferences, List methods, + private MethodReference getFactoryMethod(List mapperReferences, List methods, Type returnType) { - FactoryMethod result = null; + MethodReference result = null; for ( Method method : methods ) { if ( !method.requiresImplementation() && !method.isIterableMapping() && !method.isMapMapping() && method.getMappings().isEmpty() && method.getParameters().isEmpty() ) { @@ -225,7 +224,7 @@ public class MapperCreationProcessor implements ModelElementProcessor ${name}(<#list parameters as param><@i return<#if returnType.name != "void"> null; } - <#if !existingInstanceMapping> - ${resultType.name} ${resultName} = <#if factoryMethod??><@includeModel object=factoryMethod/><#else>new ${resultType.name}(); - + <#if !existingInstanceMapping>${resultType.name} ${resultName} = <#if factoryMethod??><@includeModel object=factoryMethod/><#else>new ${resultType.name}(); <#if (sourceParameters?size > 1)> <#list sourceParameters as sourceParam> if ( ${sourceParam.name} != null ) { diff --git a/processor/src/main/resources/org.mapstruct.ap.model.FactoryMethod.ftl b/processor/src/main/resources/org.mapstruct.ap.model.FactoryMethod.ftl deleted file mode 100644 index fd5aa5a40..000000000 --- a/processor/src/main/resources/org.mapstruct.ap.model.FactoryMethod.ftl +++ /dev/null @@ -1,21 +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. - ---> -<#if hasDeclaringMapper>${mapperVariableName}.${name}() \ No newline at end of file