diff --git a/processor/src/main/java/org/mapstruct/ap/builtin/BuiltInMappingMethods.java b/processor/src/main/java/org/mapstruct/ap/builtin/BuiltInMappingMethods.java index cb60a829e..c210346ff 100644 --- a/processor/src/main/java/org/mapstruct/ap/builtin/BuiltInMappingMethods.java +++ b/processor/src/main/java/org/mapstruct/ap/builtin/BuiltInMappingMethods.java @@ -18,7 +18,7 @@ */ package org.mapstruct.ap.builtin; -import org.mapstruct.ap.model.BuiltInMethod; +import org.mapstruct.ap.model.source.BuiltInMethod; import java.util.HashSet; import org.mapstruct.ap.model.common.TypeFactory; diff --git a/processor/src/main/java/org/mapstruct/ap/builtin/CalendarToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/builtin/CalendarToXmlGregorianCalendar.java index 9c5e4a150..ed3557045 100644 --- a/processor/src/main/java/org/mapstruct/ap/builtin/CalendarToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/builtin/CalendarToXmlGregorianCalendar.java @@ -18,7 +18,7 @@ */ package org.mapstruct.ap.builtin; -import org.mapstruct.ap.model.BuiltInMethod; +import org.mapstruct.ap.model.source.BuiltInMethod; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.Set; diff --git a/processor/src/main/java/org/mapstruct/ap/builtin/DateToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/builtin/DateToXmlGregorianCalendar.java index e4151a576..f845a82e5 100644 --- a/processor/src/main/java/org/mapstruct/ap/builtin/DateToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/builtin/DateToXmlGregorianCalendar.java @@ -18,7 +18,7 @@ */ package org.mapstruct.ap.builtin; -import org.mapstruct.ap.model.BuiltInMethod; +import org.mapstruct.ap.model.source.BuiltInMethod; import java.util.Date; import java.util.GregorianCalendar; import java.util.Set; diff --git a/processor/src/main/java/org/mapstruct/ap/builtin/JaxbElemToValue.java b/processor/src/main/java/org/mapstruct/ap/builtin/JaxbElemToValue.java index 2b86586ce..a59f98c49 100644 --- a/processor/src/main/java/org/mapstruct/ap/builtin/JaxbElemToValue.java +++ b/processor/src/main/java/org/mapstruct/ap/builtin/JaxbElemToValue.java @@ -18,7 +18,7 @@ */ package org.mapstruct.ap.builtin; -import org.mapstruct.ap.model.BuiltInMethod; +import org.mapstruct.ap.model.source.BuiltInMethod; import javax.xml.bind.JAXBElement; import org.mapstruct.ap.model.common.Parameter; import org.mapstruct.ap.model.common.Type; diff --git a/processor/src/main/java/org/mapstruct/ap/builtin/ListOfJaxbElemToListOfValue.java b/processor/src/main/java/org/mapstruct/ap/builtin/ListOfJaxbElemToListOfValue.java index eb20bf722..20512125b 100644 --- a/processor/src/main/java/org/mapstruct/ap/builtin/ListOfJaxbElemToListOfValue.java +++ b/processor/src/main/java/org/mapstruct/ap/builtin/ListOfJaxbElemToListOfValue.java @@ -18,7 +18,7 @@ */ package org.mapstruct.ap.builtin; -import org.mapstruct.ap.model.BuiltInMethod; +import org.mapstruct.ap.model.source.BuiltInMethod; import java.util.List; import javax.xml.bind.JAXBElement; import org.mapstruct.ap.model.common.Parameter; diff --git a/processor/src/main/java/org/mapstruct/ap/builtin/StringToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/builtin/StringToXmlGregorianCalendar.java index f7993c2a3..31f97b24e 100644 --- a/processor/src/main/java/org/mapstruct/ap/builtin/StringToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/builtin/StringToXmlGregorianCalendar.java @@ -21,7 +21,7 @@ package org.mapstruct.ap.builtin; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; -import org.mapstruct.ap.model.BuiltInMethod; +import org.mapstruct.ap.model.source.BuiltInMethod; import java.util.GregorianCalendar; import java.util.Set; import javax.xml.datatype.DatatypeConfigurationException; diff --git a/processor/src/main/java/org/mapstruct/ap/builtin/XmlGregorianCalendarToCalendar.java b/processor/src/main/java/org/mapstruct/ap/builtin/XmlGregorianCalendarToCalendar.java index 2adbc808c..9125b94e7 100644 --- a/processor/src/main/java/org/mapstruct/ap/builtin/XmlGregorianCalendarToCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/builtin/XmlGregorianCalendarToCalendar.java @@ -18,7 +18,7 @@ */ package org.mapstruct.ap.builtin; -import org.mapstruct.ap.model.BuiltInMethod; +import org.mapstruct.ap.model.source.BuiltInMethod; import java.util.Calendar; import javax.xml.datatype.XMLGregorianCalendar; import org.mapstruct.ap.model.common.Parameter; diff --git a/processor/src/main/java/org/mapstruct/ap/builtin/XmlGregorianCalendarToDate.java b/processor/src/main/java/org/mapstruct/ap/builtin/XmlGregorianCalendarToDate.java index 9fd03e4b3..17c9de05f 100644 --- a/processor/src/main/java/org/mapstruct/ap/builtin/XmlGregorianCalendarToDate.java +++ b/processor/src/main/java/org/mapstruct/ap/builtin/XmlGregorianCalendarToDate.java @@ -18,7 +18,7 @@ */ package org.mapstruct.ap.builtin; -import org.mapstruct.ap.model.BuiltInMethod; +import org.mapstruct.ap.model.source.BuiltInMethod; import java.util.Date; import javax.xml.datatype.XMLGregorianCalendar; import org.mapstruct.ap.model.common.Parameter; diff --git a/processor/src/main/java/org/mapstruct/ap/builtin/XmlGregorianCalendarToString.java b/processor/src/main/java/org/mapstruct/ap/builtin/XmlGregorianCalendarToString.java index a4386e463..515d89f93 100644 --- a/processor/src/main/java/org/mapstruct/ap/builtin/XmlGregorianCalendarToString.java +++ b/processor/src/main/java/org/mapstruct/ap/builtin/XmlGregorianCalendarToString.java @@ -18,7 +18,7 @@ */ package org.mapstruct.ap.builtin; -import org.mapstruct.ap.model.BuiltInMethod; +import org.mapstruct.ap.model.source.BuiltInMethod; import javax.xml.datatype.XMLGregorianCalendar; import org.mapstruct.ap.model.common.ConversionContext; import org.mapstruct.ap.model.common.Parameter; diff --git a/processor/src/main/java/org/mapstruct/ap/model/Mapper.java b/processor/src/main/java/org/mapstruct/ap/model/Mapper.java index c571c858d..12079dc72 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/Mapper.java +++ b/processor/src/main/java/org/mapstruct/ap/model/Mapper.java @@ -18,6 +18,7 @@ */ package org.mapstruct.ap.model; +import org.mapstruct.ap.model.source.BuiltInMethod; import java.util.ArrayList; import java.util.Collection; import java.util.List; 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 550ecf9f5..90550fefe 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/MethodReference.java +++ b/processor/src/main/java/org/mapstruct/ap/model/MethodReference.java @@ -18,6 +18,7 @@ */ package org.mapstruct.ap.model; +import org.mapstruct.ap.model.source.BuiltInMethod; import java.util.HashSet; import java.util.Set; import org.mapstruct.ap.model.common.ConversionContext; diff --git a/processor/src/main/java/org/mapstruct/ap/model/source/BasicMethod.java b/processor/src/main/java/org/mapstruct/ap/model/source/BasicMethod.java index 9355d1619..fbbf4312c 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/source/BasicMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/model/source/BasicMethod.java @@ -26,30 +26,71 @@ import org.mapstruct.ap.model.common.Parameter; import org.mapstruct.ap.model.common.Type; /** + * This interface makes available common method properties and a matching method * + * There are 2 known implementors: {@link BuiltInMethod} and {@link Method} * @author Sjaak Derksen */ public interface BasicMethod { - /** + /** + * Checks whether the provided sourceType and provided targetType match with the parameter respectively + * return type of the method. The check also should incorporate wild card and generic type variables * - * @param sourceType - * @param targetType - * @return + * @param sourceType the sourceType to match to the parameter + * @param targetType the targetType to match to the returnType + * + * @return true when match */ boolean matches( Type sourceType, Type targetType ); - List getSourceParameters(); - + /** + * Returns the mapper type declaring this method if it is not declared by the mapper interface currently processed + * but by another mapper imported via {@code Mapper#users()}. + * + * @return The declaring mapper type + */ Type getDeclaringMapper(); + /** + * Returns then name of the method. + * + * @return method name + */ String getName(); + /** + * In contrast to {@link #getSourceParameters()} this method returns all parameters + * + * @return all parameters + */ List getParameters(); - Type getReturnType(); + /** + * returns the list of 'true' source parameters excluding the parameter(s) that is designated as + * target by means of the target annotation {@link #getTargetParameter() }. + * + * @return list of 'true' source parameters + */ + List getSourceParameters(); + /** + * Returns the parameter designated as target parameter (if present) {@link #getSourceParameters() } + * @return target parameter (when present) null otherwise. + */ Parameter getTargetParameter(); + /** + * Returns the {@link Accessibility} of this method. + * + * @return the {@link Accessibility} of this method + */ Accessibility getAccessibility(); + + /** + * Returns the return type of the method + * + * @return return type + */ + Type getReturnType(); } diff --git a/processor/src/main/java/org/mapstruct/ap/model/BuiltInMethod.java b/processor/src/main/java/org/mapstruct/ap/model/source/BuiltInMethod.java similarity index 81% rename from processor/src/main/java/org/mapstruct/ap/model/BuiltInMethod.java rename to processor/src/main/java/org/mapstruct/ap/model/source/BuiltInMethod.java index 0cb344f1b..3d05c84a5 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/BuiltInMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/model/source/BuiltInMethod.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.ap.model; +package org.mapstruct.ap.model.source; import java.util.Arrays; import java.util.Collections; @@ -28,7 +28,6 @@ import org.mapstruct.ap.model.common.ConversionContext; import org.mapstruct.ap.model.common.ModelElement; import org.mapstruct.ap.model.common.Parameter; import org.mapstruct.ap.model.common.Type; -import org.mapstruct.ap.model.source.BasicMethod; import org.mapstruct.ap.util.Strings; /** @@ -43,8 +42,9 @@ public abstract class BuiltInMethod extends ModelElement implements BasicMethod /** - * method name - * @return default method name is equal to class name of build in mehtod + * {@inheritDoc } + * + * @return default method name is equal to class name of build in method name */ @Override public String getName() { @@ -52,16 +52,23 @@ public abstract class BuiltInMethod extends ModelElement implements BasicMethod } /** - * imported types default. Only used types should be added. Source and Target types are coming via - * the MethodReference + * {@inheritDoc} {@link ModelElement} * - * @return set of used types. + * This method acts as a template. It should be overridden by implementors if deviation is required. + * + * @return set of used types. Default an empty set. */ @Override public Set getImportTypes() { return Collections.emptySet(); } + /** + * {@inheritDoc} {@link BasicMethod} + * + * Default the targetType should be assignable to the returnType and the sourceType to the parameter, + * excluding generic type variables. When the implementor sees a need for this, this method can be overridden. + */ @Override public boolean matches( Type sourceType, Type targetType ) { if ( targetType.erasure().isAssignableTo( getReturnType().erasure() ) @@ -72,6 +79,7 @@ public abstract class BuiltInMethod extends ModelElement implements BasicMethod } /** + * {@inheritDoc} {@link BasicMethod} * * @return all parameters are source parameters for build-in methods. */ @@ -81,7 +89,10 @@ public abstract class BuiltInMethod extends ModelElement implements BasicMethod } /** - * declaring mapper is always null, being the MapperImpl + * {@inheritDoc} {@link BasicMethod} + * + * declaring mapper is always null, being the MapperImpl itself. This method should not be overridden by + * implementors * @return null */ @Override @@ -89,6 +100,9 @@ public abstract class BuiltInMethod extends ModelElement implements BasicMethod return null; } + /** + * {@inheritDoc} {@link BasicMethod} + */ @Override public List getParameters() { return Arrays.asList( new Parameter[] { getParameter() } ); @@ -117,7 +131,7 @@ public abstract class BuiltInMethod extends ModelElement implements BasicMethod } /** - * hashCode + * hashCode based on class * * @return hashCode */ @@ -141,7 +155,7 @@ public abstract class BuiltInMethod extends ModelElement implements BasicMethod } /** - * Analyzes the Java Generics type variables in the parameter do match the type variables in the build in method + * Analyzes the Java Generic type variables in the parameter do match the type variables in the build in method * same goes for the returnType. * * @param parameter source diff --git a/processor/src/main/java/org/mapstruct/ap/model/source/Method.java b/processor/src/main/java/org/mapstruct/ap/model/source/Method.java index 107200a6d..1f0561d00 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/source/Method.java +++ b/processor/src/main/java/org/mapstruct/ap/model/source/Method.java @@ -132,10 +132,7 @@ public class Method implements BasicMethod { } /** - * Returns the mapper type declaring this method if it is not declared by the mapper interface currently processed - * but by another mapper imported via {@code Mapper#users()}. - * - * @return The declaring mapper type + * {@inheritDoc} {@link BasicMethod} */ @Override public Type getDeclaringMapper() { @@ -146,16 +143,25 @@ public class Method implements BasicMethod { return executable; } + /** + * {@inheritDoc} {@link BasicMethod} + */ @Override public String getName() { return executable.getSimpleName().toString(); } + /** + * {@inheritDoc} {@link BasicMethod} + */ @Override public List getParameters() { return parameters; } + /** + * {@inheritDoc} {@link BasicMethod} + */ @Override public List getSourceParameters() { List sourceParameters = new ArrayList(); @@ -183,11 +189,15 @@ public class Method implements BasicMethod { return targetParameter != null ? targetParameter.getType() : returnType; } + /** + * {@inheritDoc} {@link BasicMethod} + */ @Override public Type getReturnType() { return returnType; } + @Override public Accessibility getAccessibility() { return accessibility; } @@ -225,6 +235,9 @@ public class Method implements BasicMethod { && equals( getResultType(), method.getSourceParameters().iterator().next().getType() ); } + /** + * {@inheritDoc} {@link BasicMethod} + */ @Override public Parameter getTargetParameter() { return targetParameter; @@ -298,10 +311,7 @@ public class Method implements BasicMethod { } /** - * - * @param sourceType - * @param targetType - * @return + * {@inheritDoc} {@link BasicMethod} */ @Override public boolean matches( Type sourceType, Type targetType ) { 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 c13cd83e7..2273930ab 100644 --- a/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java @@ -41,7 +41,7 @@ import org.mapstruct.ap.model.common.ConversionContext; import org.mapstruct.ap.conversion.ConversionProvider; import org.mapstruct.ap.conversion.Conversions; import org.mapstruct.ap.model.common.DefaultConversionContext; -import org.mapstruct.ap.model.BuiltInMethod; +import org.mapstruct.ap.model.source.BuiltInMethod; import org.mapstruct.ap.builtin.BuiltInMappingMethods; import org.mapstruct.ap.model.BeanMappingMethod; import org.mapstruct.ap.model.DefaultMapperReference;